any plugin or tool to auto fill the Args for the POJOs in intellij?

75 Views Asked by At

every time while writing the test cases i need to write all the object constructors and setters manually for ex:

Pojo.java

    public class Pojo {
        private int a;
        private int b;
        private int c;
        // getters and setters
        // equals and hashCode
        // toString
    }

PojoTest.java

//@SpringBootTest
@RunWith(SpringRunner.class)
public class PojoTest {
    @Autowired
    private Pojo p;

    @Test
    public void getValues() {
    p.setA(1);
    p.setB(2);
    assertEquals(p.getA(),1);
    }
    }

here if you look at this below code manually writing the setters

     p.setA(1);
        p.setB(2);

is there any plugin to auto fill the Args based on data types in intelliJ?

1

There are 1 best solutions below

2
Zahid Khan On

You can use instancio library for automating data setup in unit tests.

Instancio uses reflection to populate objects, including nested objects and collections. A single method call provides you with a fully populated instance of a class, ready to be used as an input to your test case

MVN Dependency:

<dependency>
    <groupId>org.instancio</groupId>
    <artifactId>instancio-junit</artifactId>
    <version>4.1.0</version>
    <scope>test</scope>
</dependency>

Example:

Pojo student = Instancio.create(Pojo.class);

Reference: https://www.instancio.org/