JUnit: Unit Testing

JUnit is used for unit testing. The unit testing is one of the testing methodologies that tests module or method that was written.

Writing the test is done by creating normal java class, except we use special annotations for it.

Note: best practice in unit testing is to have multiple tests for single method.

Let’s say you have method calculateMinAge(), it’s good idea to create multiple test methods

Unlike other java classes, JUnit test class has different structure:

@Suit or @TestRetention <– this annotation helps to include the current class file into larger test group, containing other test files

@Before <Рthis annotation can be used to initialize the objects that are used in different methods. Also the method name should be called setUp(). Ex:

@Before

public void setUp(){}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *