JUnit

You will use JUnit to run your unit tests. Let's check it.

Here is a class to be tested:

public class JUnitExample {        @Size (min = 6, max = 10,message = "Name should be between 6 and 10            characters")    private String name;    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    }

Here is a testing class:

public class JUnitTest {        private static Validator VALIDATOR;        @BeforeClass    public static void setUpClass() {        VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator();    }    @Test    public void smallName(){        JUnitExample junit = new JUnitExample();                junit.setName("Name");                Set<ConstraintViolation<JUnitExample>> cv =         VALIDATOR.validate(junit);        assertFalse(cv.isEmpty());    }        @Test public void ...

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.