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);
它仍然失敗。
我在哪裏錯了?由於
'ZigZagMatrix'看起來像什麼? – Reimeus
用'-X'標誌運行。 –
這裏是輸出:http://pastebin.com/Wp6bFZVx –