Search code examples
unit-testingjunitdependency-injectioncustom-componentjmockit

How to tell JMockit not to override behavior of custom junit runners designed for integration testing


I have the following test method

@RunWith(MyCustomJUnit4Runner.class)
public class MyIntegrationTestWithACustomIntegrationRunner{
    @Test
    public void ensureStuffIsWiredCorrectly(Dependency myDependency){

    }
}

This method is ran with a custom runner that injects the wired dependency.

JMockit also injects mocks in this scenario.

Normally I would want the jmockit behaviors, however this case I need the platform injected item rather than the mocked version.

Any advice would be appreciated.

Please feel free to comment on how I can clarify the obviously ambiguous question.

pom entries:

<dependencies>

<!-- CUSTOM INTEGRATION RUNNER -->
    <dependency>
        <groupId>com.clinkworks</groupId>
        <artifactId>neptical</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>        

    <dependency>
        <groupId>com.googlecode.jmockit</groupId>
        <artifactId>jmockit</artifactId>
        <version>1.5</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>[4.0,5.0)</version>
        <scope>test</scope>
    </dependency>

</dependencies>

Solution

  • You will have to upgrade JMockit to version 1.7 or newer:

    <dependency>
        <groupId>org.jmockit</groupId>
        <artifactId>jmockit</artifactId>
        <version>1.8</version>
        <scope>test</scope>
    </dependency