1 / 10

Unit Testing

Unit Testing. Unit Testing Options. Use N-Unit In a microsoft environment .NET… you can use their supplied N-Unit testing to test your classes Using J-Unit

Télécharger la présentation

Unit Testing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit Testing

  2. Unit Testing Options • Use N-Unit • In a microsoft environment .NET… you can use their supplied N-Unit testing to test your classes • Using J-Unit • A free download and integratable with most IDE’s is J-Unit which you can use with Java for unit testing. There are some other unit testing programs for C++, Smalltalk, Eiffel, Ada, etc… They do cost. • Writing your own Unit Testing

  3. Unit Testing Options • Write your own unit testing program. • This allows you to understand unit testing better.

  4. Creating a Unit Test Class Step 1 Create a Unit Test Class Given the class you wish to test YourClassName. Build a class called YourClassNameUnitTest that is a sub-class of YourClassName Your class Unit Test class

  5. Creating a Unit Test Class HOW Your class Step 1 – Create Unit Test Class -- HOW Simply copy your class into another class called YourClassNameUnitTest Make it a a sub-class of YourClassName In the constructor (s) remove the code and call the super-class constructor method In the other methods – rewrite them in the form shown in step 2 Unit Test class

  6. Rewriting Methods Step 2 – Rewriting Methods For all methods that are void--- simply call the super method OR eliminate them if they are not needed for other methods. These void methods should not be changing any class variables but simply doing things that do not change the state of the object. For all methods that return a value. Set up test(s) to assure the correct value is returned.

  7. Rewriting Methods Example Your class Method addit (int a, int b):int return a + b; Unit Test class Method addit (int a, int b):int int a = 4; int b = 5; int answer = super (a,b); if answer <> 9 print Error in addit; print expected, “9”; print received, answer; else print OK;

  8. Creating a Unit Test Executable Step 3 – Create a Unit Test Executable Class Your class Unit test EXEC class Unit test class

  9. Creating a Unit Test Executable Step 3 – Create a Unit Test Executable – How Decide what methods you wish to test. Remember– you will use this for the entire duration of this class …it may change over the years but this test can be run to make sure that changes to this c;ass or other classes in the system do not adversely impact this class….. It helps to keep down the ripple effect of changes

  10. Creating a Unit Test Executable Step 3 – Create a Unit Test Executable – How In the main executable routine Make an instance of the Unit Test Class Call each method in the Unit Test Class that you wish to test Remember, each unit test method may execute many different tests with different parameters.

More Related