lundi 2 septembre 2019

Spring Tests without shared beans incluencing each other?

I have two unit test-classes that each test a camunda BPM process model using @RunWith(SpringJUnit4ClassRunner.class). I use a camunda extension to catch the process model test coverage, that works with a rule:

    @Autowired
    private ProcessEngine processEngine;

    @Rule
    @ClassRule
    public static ProcessEngineRule processEngineRule;

    @PostConstruct
    public void initProcessCoverage() {
        processEngineRule = TestCoverageProcessEngineRuleBuilder.create(processEngine).build();
    }

Since the tests run with @RunWith(SpringJUnit4ClassRunner.class) I create the ProcessEngine manually in a dedicated configuration.

Now here´s the thing: both my test-classes run without issues when I run them alone. If I run them both, all Unit tests in the class with the name later in the alphabet fails. (i.e. ABCtest.java all pass, XYZtest.java all fail)

The Exception is plain:

java.lang.NullPointerException  at org.camunda.bpm.extension.process_test_coverage.model.MethodCoverage.endCoveredElement(MethodCoverage.java:76)

Upon debugging I found out, that the Objects behind this coverage rule are, upon runtime, configured wrongly: when it comes to covering the tests from the second class it is still configured to cover the tests from the first class.

Now this could be an issue with the coverage extension, but I´m pretty sure it also has something to do with how the tests are executed. When I put all the tests in one class (which is ugly as hell), they all pass. So the issue must be with how tests from different classes are handled by JUnit, I figured. But how can I influence that? What else can I try?

Approaches that did not work:

  • Ensure both test classes have completely separate configurations
  • @DirtiesContext
  • Make both test classes inherit from an abstract superclass that hold the @Rule etc (I´m just guessing at hit point)

Any help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire