Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java mvn测试找不到junit测试_Java_Maven_Junit - Fatal编程技术网

Java mvn测试找不到junit测试

Java mvn测试找不到junit测试,java,maven,junit,Java,Maven,Junit,我在junit中创建了一个简单的单元测试项目。我已经运行了mvn测试,但是当我运行时,我收到了以下消息。这是我的文件夹结构 [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ junit-tests --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-te

我在junit中创建了一个简单的单元测试项目。我已经运行了
mvn测试
,但是当我运行时,我收到了以下消息。这是我的文件夹结构

[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ junit-tests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ junit-tests ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.394 s
[INFO] Finished at: 2017-04-22T20:37:54-04:00
[INFO] Final Memory: 16M/211M
[INFO] ------------------------------------------------------------------------
我的项目结构

.                                                                                                     │/.m2/repository/org/sonatype/mcookbook/junit-tests/1.0-SNAPSHOT/junit-tests-1.0-SNAPSHOT.jar
├── pom.xml                                                                                           │[INFO] Installing /Users/ianvshuff/Code/junit/pom.xml to /Users/ianvshuff/.m2/repository/org/sonatype
├── src                                                                                               │/mcookbook/junit-tests/1.0-SNAPSHOT/junit-tests-1.0-SNAPSHOT.pom
│   └── main                                                                                          │[INFO]
│       └── java                                                                                      │[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ junit-tests ---
│           └── org                                                                                   │[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform
│               └── calculator                                                                        │ dependent!
│                   └── instant                                                                       │[INFO] skip non existing resourceDirectory /Users/ianvshuff/Code/junit/src/main/resources
│                       └── Calculator.java                                                           │[INFO]
├── target                                                                                            │[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ junit-tests ---
│   ├── classes                                                                                       │[INFO] Changes detected - recompiling the module!
│   │   └── org                                                                                       │[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform depen
│   │       └── sonatype                                                                              │dent!
│   │           └── macbook                                                                           │[INFO] Compiling 1 source file to /Users/ianvshuff/Code/junit/target/classes
│   │               └── Calculator.class                                                              │[INFO]
│   ├── junit-tests-1.0-SNAPSHOT.jar                                                                  │[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ junit-tests ---
│   ├── maven-archiver                                                                                │[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform
│   │   └── pom.properties                                                                            │ dependent!
│   └── maven-status                                                                                  │[INFO] skip non existing resourceDirectory /Users/ianvshuff/Code/junit/src/test/resources
│       └── maven-compiler-plugin                                                                     │[INFO]
│           └── compile                                                                               │[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ junit-tests ---
│               └── default-compile                                                                   │[INFO] No sources to compile
│                   ├── createdFiles.lst                                                              │[INFO]
│                   └── inputFiles.lst                                                                │[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ junit-tests ---
└── test                                                                                              │[INFO] No tests to run.
    └── main                                                                                          │[INFO] Skipping execution of surefire because it has already been run for this configuration
        └── java                                                                                      │[INFO] ------------------------------------------------------------------------
            └── org                                                                                   │[INFO] BUILD SUCCESS
                └── calculator                                                                        │[INFO] ------------------------------------------------------------------------
                    └── instant                                                                       │[INFO] Total time: 1.394 s
                        └── CalculatorTest.java
这是我的课和测试课

Calculator.java

package org.sonatype.macbook;
public class Calculator {
        public int evaluate(String expression) {
                int sum = 0;
                for (String summand: expression.split("\\+"))
                        sum += Integer.valueOf(summand);
                return sum;
        }
}
CalculatorTest.java

package org.calculator.instant;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class CalculatorTest {
        @Test
        public void evaluatesExpression() {
                Calculator calculator = new Calculator();
                int sum = calculator.evaluate("1+2+3");
                assertEquals(6, sum);
        }
}
pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
        http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.calculator.instant</groupId>
        <artifactId>junit-tests</artifactId>
        <packaging>jar</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>junit-tests</name>
        <dependencies>
                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.12</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>
</project>

4.0.0
org.calculator.instant
junit测试
罐子
1.0-快照
junit测试
朱尼特
朱尼特
4.12
测试

一般来说,我是junit和java的新手,所以我不明白为什么它们没有运行。

Maven项目结构应该是:
src/main/java/package/class
src/test/java/package/testclass
。你的结构不正确。请更新。Maven项目结构应为:
src/main/java/package/class
src/test/java/package/testclass
。你的结构不正确。请更新它。

您的测试类需要在
src/test/java
中;不是
test/main/java
@SteveC,这是不正确的,请查看接受的答案。您的测试类需要在
src/test/java
中;不是
test/main/java
@SteveC,这是不正确的,请查看接受的答案。