Ticket #16567: 16567.fixup1.1.patch

File 16567.fixup1.1.patch, 2.3 KB (added by taylor.smock, 4 years ago)

Add -Djunit.jupiter.extensions.autodetection.enabled=true as a JVM argument. This automatically registers the JMockit JUnit5 extension, which clears mocks between tests (otherwise, you can have a ton of mocks for the same code)

  • build.xml

     
    462462                            <jvmarg value="${jacocoagent@{testfamily}@{testITsuffix}}" if:set="jacocoagent@{testfamily}@{testITsuffix}" />
    463463                            <jvmarg value="-Dfile.encoding=UTF-8"/>
    464464                            <jvmarg value="-javaagent:${test.dir}/lib/jmockit.jar"/>
     465                        <jvmarg value="-Djunit.jupiter.extensions.autodetection.enabled=true"/>
    465466                            <jvmarg value="--add-modules" if:set="isJava9" unless:set="isJava11" />
    466467                            <jvmarg value="java.activation,java.se.ee" if:set="isJava9" unless:set="isJava11" />
    467468                            <jvmarg value="--add-exports" if:set="isJava9" unless:set="noJavaFX" />
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

     
    103103    private boolean territories;
    104104    private boolean metric;
    105105    private boolean main;
     106    /**
     107     * This boolean is only used to indicate if JUnit5 is used in a test. If it is,
     108     * we must not call after in {@link JOSMTestRules.CreateJosmEnvironment#evaluate}.
     109     * TODO: Remove JUnit4 as a whole sometime after 2021-01-01 (~6 month lead time for plugins)
     110     */
     111    private boolean junit5;
    106112
    107113    /**
    108114     * Disable the default timeout for this test. Use with care.
     
    437443
    438444    @Override
    439445    public void beforeEach(ExtensionContext context) throws Exception {
     446        this.junit5 = true;
    440447        Statement temporaryStatement = new Statement() {
    441448            @Override
    442449            public void evaluate() throws Throwable {
     
    454461
    455462    @Override
    456463    public void afterEach(ExtensionContext context) throws Exception {
    457         // do nothing for now
     464        after();
    458465    }
    459466
    460467    /**
     
    689696            try {
    690697                base.evaluate();
    691698            } finally {
    692                 after();
     699                if (!junit5) {
     700                    after();
     701                }
    693702            }
    694703        }
    695704    }