如果org.mortbay冲突问题已经解决,而又遇到gwt.junit.JUnitFatalLaunchException(错误例子如下)
com.google.gwt.junit.JUnitFatalLaunchException: The test class 'com.google.gwt.sample.stockwatcher.clients.StockWatcherTest' was not found in module 'com.google.gwt.sample.stockwatcher.StockWatcher'; no compilation unit for that type was seen
at com.google.gwt.junit.JUnitShell.checkTestClassInCurrentModule(JUnitShell.java:743)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1346)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:1309)
at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:650)
at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:441)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
错误原因:找不到测试类和被测试类的关联(笔者这边的情况是被测试类在src/com.google.gwt.sample.stockwatcher.client下,而测试类写在了test/com.google.gwt.sample.stockwatcher.clients下)
检查以及解决方法:
1、把测试类拷贝到被测试类的同一个目录下,简单粗暴,但把测试代码写到src底下,非常丑陋。
2、检查测试类和被测试类所在包名称是否匹配(文件夹不需匹配,被测试类都在src下,测试类都在test下)
3、如果2检查过但仍出现这个错误,Java Build Path -> Source里面没有配置src和test目录
这个错误搞定后测试就成功了(GWT单元测试速度真的不敢恭维)
Starting http://192.168.0.100:59172/com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/junit.html?gwt.codesvr=192.168.0.100:59170 on browser FF3
200 - GET /com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/junit.html?gwt.codesvr=192.168.0.100:59170 (192.168.0.100) 2380 bytes
200 - GET /com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.nocache.js (192.168.0.100) 6341 bytes
logging for HtmlUnit thread
[WARN] Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://192.168.0.100:59172/com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.nocache.js', but got 'application/x-javascript'.
200 - GET /com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/hosted.html?com_google_gwt_sample_stockwatcher_StockWatcher_JUnit (192.168.0.100) 11478 bytes
200 - GET /com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/gwt/clean/clean.css (192.168.0.100) 29306 bytes
200 - GET /com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/gwt/standard/standard.css (192.168.0.100) 26953 bytes
Module com.google.gwt.sample.stockwatcher.StockWatcher.JUnit has been loaded
200 - POST /com.google.gwt.sample.stockwatcher.StockWatcher.JUnit/junithost (192.168.0.100) 425 bytes
All clients connected (Limiting future permutations to: gecko1_8)