Collection of useful JUnit methods for day by day testing

This collection of JUnit methods helps developers to check data and to create robust Java applications (and Unit tests).

Methods

assertEquals()  Uses the equals() method to verify that objects are identical
assertTrue() Checks if the condition is true.
assertFalse() Checks if the condition is false.
assertNull() Checks if the object is null
assertNotNull() Checks if the object is not null.
assertNotEquals() Uses the equals() method to verify that objects are not identical
assertArrayEquals() Checks if two arrays contain the same objects in the same order.
assertSame() Uses == to verify that objects are the same
assertNotSame() Uses == to verify that objects are not the same.
assertThat() An entry point to the matchers-based assertions which we will discuss in Section 6.6.

 Examples

@Test @Parameters(method = "nbOfGamesWon")
@Parameters(method = "nbOfGamesWon")
@Test(expected = IllegalArgumentException.class)
    @Test
    public void testYYMMDDtoMMDDYY(){
        assertEquals("020115", DateUtils.convertDate("150201", DateUtils.FORMATS.YYMMDD, DateUtils.FORMATS.MMDDYY));
    }
    @Test(expected = IllegalArgumentException.class)
    public void checkEmailError() {InputValidator.checkEmail("transport.mail.com");}

Import

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

Pom file

	        <dependency>
		    <groupId>junit</groupId>
		    <artifactId>junit</artifactId>
		    <version>4.11</version>
		    <scope>test</scope>
		<dependency>