JUnit测试失败

时间:2014-04-19 21:07:42

标签: java junit

我正在学习单元测试。我创建了一个简单的测试:

public class ZigZagTest {

  @Test
  public void testZigZag() {
    final int size = 2;

    int[][] correctZigZag = new int[][] {
        {0, 0},
        {0, 1},
        {1, 0},
        {1, 1}
    };

    int[][] zigzag = ZigZagMatrix.getZigZagMatrix(size);

    for(int i = 0; i < size*size; i++) {
      assertEquals(correctZigZag[i][0], zigzag[i][0]);
      assertEquals(correctZigZag[i][1], zigzag[i][1]);
    }
  }

}

但是当我正在运行测试时,它失败了:

/usr/lib/jvm/java-7-oracle/bin/java -Dmaven.home=/usr/share/maven -Dclassworlds.conf=/usr/share/maven/bin/m2.conf -Didea.launcher.port=7552 -Didea.launcher.bin.path=/home/victor/bin/IDEA/bin -Dfile.encoding=UTF-8 -classpath /usr/share/maven/boot/plexus-classworlds-2.x.jar:/home/victor/bin/IDEA/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.1 --offline test
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Compressor 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ Compressor ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ Compressor ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) @ Compressor ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/victor/Projects/Compressor/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ Compressor ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ Compressor ---
[INFO] Surefire report directory: /home/victor/Projects/Compressor/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running ZigZagTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.042 sec <<< FAILURE!

Results :

Failed tests:   ZigZagTest.testZigZag(): org/junit/Assert

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.319s
[INFO] Finished at: Sun Apr 20 00:05:02 EEST 2014
[INFO] Final Memory: 8M/78M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project Compressor: There are test failures.
[ERROR] 
[ERROR] Please refer to /home/victor/Projects/Compressor/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Process finished with exit code 1

我试图评论这些断言,并用

替换它
  

的assertEquals(1,1);

但它仍然失败。

我哪里错了?感谢

1 个答案:

答案 0 :(得分:1)

已在评论中解决:

  

我刚刚进行了重建并得到了有关ClassNotFoundException org.junit.Assert的错误。问题在于pom.xml中不正确的junit依赖版本。