2014-04-19 291 views
0

我正在学习单元测试。我创建了一个简单的测试: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);

它仍然失败。

我在哪里错了?由于

+0

'ZigZagMatrix'看起来像什么? – Reimeus

+0

用'-X'标志运行。 –

+0

这里是输出:http://pastebin.com/Wp6bFZVx –

回答

1

在评论中解决:

我刚才提出重建,得到了错误有关的ClassNotFoundException org.junit.Assert。问题出在pom.xml中junit依赖关系的版本不正确。