简体   繁体   English

Pitest JUnit5 突变失败

[英]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.我必须将一些测试从 JUnit 4 升级到 JUnit 5,并且还要将 Pitest 的版本从 1.4.0 更新到 1.6.0。

With the tests on JUnit 4 and pitest 1.4.0 tests everything works.通过对 JUnit 4 和 Pitest 1.4.0 的测试,一切正常。 After migrating the test to JUnit 5, with some modification, test are passing but, when I do pitest the tests with pojo validation fails.将测试迁移到 JUnit 5 后,经过一些修改,测试通过了,但是当我进行 ptest 测试时,使用 pojo 验证的测试失败。

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?有任何想法吗?

As of pitest 1.4.7 upwards, the coverage system pitest uses introduces a synthetic field to each class to hold the coverage probes.从 Pitest 1.4.7 开始,覆盖系统 Pitest 使用为每个类引入一个合成字段来保存覆盖探针。 This is a common approach, also used by coverage systems such as jacoco.这是一种常见的方法,也被 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.顺便说一句,pitest 的最新版本是 1.8.0。 I would recomend upgrading to this rather than 1.6.0.我建议升级到这个而不是 1.6.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM