Rain03
Rain03

Reputation: 1

Pitest JUnit5 mutation fails

I have the following question:

I have to upgrade some tests from JUnit 4 to JUnit 5 and, also, update the version of pitest from 1.4.0 to 1.6.0.

With the tests on JUnit 4 and pitest 1.4.0 tests everything works. After migrating the test to JUnit 5, with some modification, test are passing but, when I do pitest the tests with pojo validation fails.

Example of a test:

    @BeforeEach
    public void setup() {
        pojoClasses = PojoClassFactory.getPojoClassesRecursively(POJO_PACKAGE, pojoClass -> pojoClass.getName().endsWith("Dto"));

        pojoValidator = new PojoValidator();

        pojoValidator.addRule(new NoPublicFieldsRule());
        pojoValidator.addRule(new NoPrimitivesRule());
        pojoValidator.addRule(new NoStaticExceptFinalRule());
        pojoValidator.addRule(new GetterMustExistRule());
        pojoValidator.addRule(new SetterMustExistRule());

        pojoValidator.addTester(new DefaultValuesNullTester());
        pojoValidator.addTester(new SetterTester());
        pojoValidator.addTester(new GetterTester());
    }

    @Test
    public void testPojoStructureAndBehavior() {
        for (PojoClass pojoClass : pojoClasses) {
            pojoValidator.runValidation(pojoClass);
        }
    }

And the error I got:

java.lang.AssertionError: Primitive fields (byte, short, int, long, float, double, boolean, char) not allowed [PojoFieldImpl [field=private static transient int something.something.something.packagename.classname.$$pitCoverageProbeSize, fieldGetter=null, fieldSetter=null]]

Any ideas?

Upvotes: 0

Views: 938

Answers (1)

henry
henry

Reputation: 6096

As of pitest 1.4.7 upwards, the coverage system pitest uses introduces a synthetic field to each class to hold the coverage probes. This is a common approach, also used by coverage systems such as jacoco.

Most reflection based libraries filter out synthetic fields. It seems that the code your are running is not well behaved. If it is your own code, you will need to update it to ignore synthetic fields. If not, you will need to contact the library maintainer.

Incidently, the latest version of pitest is 1.8.0. I would recomend upgrading to this rather than 1.6.0.

Upvotes: 1

Related Questions