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(){}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s