<scope>test</scope> causes error when Mavn executes test
PHPz
PHPz 2017-05-17 10:08:51
0
1
974

When learning maven test, when executing mvn test, org.junit will not be found
It has been introduced in pom.xml

    <dependencies>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

The error message is as follows

The file directory is as follows

The following files exist in the hello directory

Where GreeterTest is the test

Executing mvn compile or mvn package will also report an error

When the scope that junit depends on in pom.xml is removed, compilation and testing can be successful.

    <dependencies>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

What is the reason for this? Does maven compile *Test files at the same time when executing compile? So why can't mvn test succeed?
Isn’t mvn test automatically executing the *Test file? And scope test determines that junit

will be introduced during testing.
PHPz
PHPz

学习是最好的投资!

reply all(1)
phpcn_u1582

This problem is actually caused by you not being familiar with the Maven file structure. Test classes are generally placed under src/test/java instead of src/main/java. When Maven is compiling, it is placed under src/main/java It does not reference the jar of <scope>test</scope>, but compiling the test under src/test/java will reference the jar of <scope>test</scope>

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template