Skip to content

Repository files navigation

javabean-tester

Java CI Coverage Status Renovate enabled Maven Central Project Stats Apache 2

Latest Release

You can download source binaries from our releases page and release binaries from Maven central

Alternatively you can pull it using Maven:

<dependency>
  <groupId>com.github.hazendaz</groupId>
  <artifactId>javabean-tester</artifactId>
  <version>2.12.1</version>
  <scope>test</scope>
</dependency>

Or using Gradle:

testImplementation 'com.github.hazendaz:javabean-tester:2.12.1'

Information for other build frameworks can be found here.

Requires java 17+

Sites

Javabean Tester is a reflection based library for testing java beans. Effectively test constructors, clear, getters/setters, hashcode, toString, equals, and serializable are correct.

Left Codebox and fork network

Portions of the initial baseline (getter/setter test) were contributed by Rob Dawson (codebox).
This project has since evolved into a full-featured version and is the primary maintained fork.
Pull requests and issues are welcome; the original CodeBox version exists separately and lacks the additional features here.

See historical discussion here:

Builder API documentation

The fluent builder is the supported entry point for configuring tests.

Builder quick start

Run the standard bean checks:

JavaBeanTester.builder(Test.class).test();

Add equals, hashCode, toString, and canEqual verification:

JavaBeanTester.builder(Test.class).checkEquals().loadData().test();

Test two existing instances:

JavaBeanTester.builder(Test.class).loadData().testEquals(instance1, instance2);

Skip selected bean properties:

JavaBeanTester.builder(Test.class).checkEquals().loadData().skip("fieldToSkip").test();

Use an explicit extension type when you do not want the generated one:

JavaBeanTester.builder(Test.class, Extension.class).checkEquals().test();

Test a private constructor:

JavaBeanTester.builder(Test.class).testPrivateConstructor();

Builder options

  • checkEquals() enables equals/hashCode/toString/canEqual verification.
  • checkSerializable() fails fast when the class under test is not serializable and validates serializable round-tripping.
  • loadData() asks the tester to populate nested values when sample data is needed.
  • skipStrictSerializable() relaxes the equality assertion performed after serialization for complex object graphs.
  • skip("propertyName") excludes specific bean properties from getter/setter checks.

About

JavaBean Tester

Resources

Stars

18 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages