Model Tester is a utility for automatically testing model classes.
- If you are using Gradle just add the following dependency to your
build.gradle
.
testImplementation "com.github.joutvhu:model-tester:1.0.5"
- Or add the following dependency to your
pom.xml
if you are using Maven.
<dependency>
<groupId>com.github.joutvhu</groupId>
<artifactId>model-tester</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
- Provide model class to be used for testing.
- Set up test options.
- Use method
test()
ortestAndThrows()
to execute the tester.
public class UserTest {
@Test
public void test_all() {
Assertions.assertTrue(ModelTester.allOf(User.class).test());
}
@Test
public void test_and_throws() {
ModelTester.allOf(User.class).testAndThrows();
}
@Test
public void test_safe() {
ModelTester.safeOf(User.class).testAndThrows();
}
@Test
public void test_custom() {
ModelTester.of(User.class)
.constructors()
.exclude("getId", "setId")
.equalsMethod()
.hashCodeMethod()
.toStringMethod()
.testAndThrows();
}
}