Getting Started

1. Introduction of Pojo Tester

Pojo Tester is a powerful and lightweight open-source Java library designed to simplify the process of testing Plain Old Java Objects (POJOs). It helps developers automate the validation of Java objects by verifying common scenarios such as constructors, getters, setters, equals, hashCode, and toString methods. The library ensures that POJOs adhere to standard conventions, providing a quick way to perform basic checks without the need for extensive test cases.

The original version of Pojo Tester was created by the author of Pojo.pl, which is a fantastic tool that helped the Java community with POJO validation. However, the original version was not fully updated to support newer Java versions like Java 21. This project, part of the OpenJavaLibs initiative, aims to continue the work by updating and maintaining the library to ensure it works seamlessly with Java 21 and beyond.

By reducing the boilerplate code associated with manual POJO validation, Pojo Tester offers an efficient and scalable solution for software developers, making it easier to maintain and test Java classes with minimal effort. Whether you are working on small projects or large enterprise applications, Pojo Tester provides the necessary tools to ensure your POJOs are consistent, correctly implemented, and ready for use.

2. Supported Java Version

Pojo Tester now supports Java 21 and higher, making it compatible with the latest features and improvements introduced in Java 21. The library is continuously updated to ensure compatibility with modern Java versions, providing developers with the latest tools for testing POJOs in the evolving Java ecosystem.

3. How to Use It

To start using Pojo Tester in your project, follow these simple steps:

  1. Add the Dependency:

    • If you're using Maven, add the following dependency to your pom.xml file:

    <dependency>
        <groupId>OpenJavaLibs</groupId>
        <artifactId>pojo-tester</artifactId>
        <version>21.0.0</version>  <!-- Ensure you use the latest version -->
        <scope>test</scope>
    </dependency>
    
    <repositories>
        <repository>
            <id>openjavalibs-repo</id>
            <url>https://github.com/OpenJavaLibs/pojo-tester</url>
        </repository>
    </repositories>
    • For Gradle, add the following to your build.gradle:

    gradleCopy codetestImplementation 'OpenJavaLibs:pojo-tester:21.0.0'  // Replace with the latest version
  2. Write Tests: Create a test class in your project. In the test, use the PojoTester class to validate the POJOs:

    import org.junit.jupiter.api.Test;
    import static com.java.pojo.api.assertion.Assertions.assertPojoMethodsFor;
    import com.java.pojo.api.assertion.Method;
    
    class PojoTester {
        
        @Test
        public void Should_Pass_All_Pojo_Tests() {    
            // given    
            final Class<?> classUnderTest = Pojo.class;    
            // then    
            assertPojoMethodsFor(classUnderTest).areWellImplemented();}
        }
    }

That's it! The library will ensure your POJOs adhere to best practices by testing common methods and properties.

4. Downloads

Download latest version (21.0.0)

Features

  • Original Source Code of Pojo Tester compatible with Java 21

  • All Unit Test Cases (1122 passed, 4 skipped)

Last updated