Understanding Unit Testing in Software Engineering

Slide Note
Embed
Share

Concept Software is a discipline comprising various code pieces. Testing these codes together is complex but vital in Software Engineering. The process includes early testing like unit tests, pairwise/multiple component testing, module testing, integration testing, user tests, alpha tests, beta tests, system tests, and more. Unit tests play a crucial role by ensuring individual code pieces function well before integration. Approaching unit testing includes ensuring code coverage, testing main code paths, error paths, alternate paths, ranges, and more. The industry utilizes various frameworks for unit testing, such as unittest and pytest for Python, Junit for Java, Nunit, and many others. Setting up test conditions, calling functions to be tested, and checking results are key steps in unit testing.


Uploaded on Oct 09, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Unit Testing

  2. Concept Software is composed of many pieces of code Testing all the code together is complex In Software Engineering, we treat testing as a discipline and skill set of its own, and test at each stage of the Software Process - Early testing: Unit test - Pairwise/ multiple component Testing Module Testing Integration Testing Also: User Tests Alpha Tests Beta Tests - Application Level testing System Test

  3. Unit Test Unit tests are designed to ensure that individual pieces of code are well testing BEFORE they are integrated into the larger application Unit tests are intended to be written (and executed) by the programmers themselves It is part of the Personal Quality expectation that you ensure your code works well before submitting for integration with the application i.e. Never check in broken code! This is all written/ run by the Software Engineer (not the Test/ QA group)!

  4. Approach Ensure code coverage Branches tested Test main code path Test error paths (and other alternate paths) Test ranges, out-of-range etc. Corollary: If the parts are bad you re out of luck! If the parts are good, the whole (can be) good

  5. Unittests in the industry Many frameworks In SWEN-250 Python: Built in unittests in the skeleton code - unittest Designed to automatically test your work - pytest Foundation for CI Java: - Continuous Integration (more on that later) - Junit Multiple: Nunit And lots of others

  6. Generally Set up the test conditions (usually data) char output_array[MAXLINE + 1] = "" ; // initialize to empty line to be safe char testline1[] = "A" ; // test single char line char testline2[] = "" ; // test empty line char testline3[] = "Typical line to be copied." ; char testline4[] = "\n\n\n" ; Call the function(s) to be tested copy( output_array, testline1 ) ; Check the result (often using assert as shorthand for if/then/else to test result) if ( assert( !strcmp( output_array, testline1 ), "Unit test for one character string" ) ) passcount++ ; else failcount++ ;

Related


More Related Content