JUnit – Assert if a property exists in a class

Includes hamcrest-library and test the class property and its value with hasProperty() : P.S Tested with JUnit 4.12 and hamcrest-library 1.3 ClassPropertyTest.java package com.mkyong; import org.junit.Test; import java.util.Arrays; import java.util.List; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasProperty; import static org.junit.Assert.assertThat; public class ClassPropertyTest { //Single Object @Test public void testClassProperty() { Book obj …

Read more