vendredi 8 janvier 2021

maven test fails with nullpointer but junit 5 ok

I'm having a strange problem with maven test with Junit 5.

I'd created the test suites with junit tools for each method, every test starts like this

private Class2Test createTestSubject() {
        return new Class2Test();
    }

    public void test1() throws Exception {
        Class2Test testSubject;
        String result;

        // default test
        testSubject = createTestSubject();
        result = testSubject.getData();
        //testing, assert
}

The line result = testSubject.getData(); returns a NullPointerException

When I execute the same test via eclipse finish ok. The surefire plugin are defined

        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <dependencies>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.7.0</version>
            </dependency>                
        </dependencies>
        <configuration>
                <systemPropertyVariables>
                    <entorno>${project.basedir}\resources\maqueta.properties</entorno>
                    <hibernate>${project.basedir}\resources\hibernate.cfg.xml</hibernate>
                </systemPropertyVariables>
                <parallel>classes</parallel>
                <threadCount>10</threadCount>
            </configuration>
    </plugin>

I'd tried to change the declaration of the object to dogde the nullpointer but it fails.

Aucun commentaire:

Enregistrer un commentaire