GWT单元测试 gwt.junit.JUnitFatalLaunchException

如果org.mortbay冲突问题已经解决,而又遇到gwt.junit.JUnitFatalLaunchException(错误例子如下)

 

<span style="font-family: SimSun; font-size: 16px;" mce_style="font-family: SimSun; font-size: 16px;">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) </span>错误原因:找不到测试类和被测试类的关联(笔者这边的情况是被测试类在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单元测试速度真的不敢恭维)

 

<span style="font-family: SimSun; font-size: 16px;" mce_style="font-family: SimSun; font-size: 16px;">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)</span>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JUnit、 Guice、 Mockito 高效组合测试框架。如果你使用 Google Guice,或者如果你的GWT应用程序使用 Gin,那么,Jukito 是解决你的单元测试头痛的灵丹妙药。现在,你可进行如下测试:@RunWith(JukitoRunner.class) public class EmailSystemTest {   @Inject EmailSystemImpl emailSystem;   Email dummyEmail;      @Before   public void setupMocks(       IncomingEmails incomingEmails,        EmailFactory factory) {     dummyEmail = factory.createDummy();     when(incomingEmails.count()).thenReturn(1);     when(incomingEmails.get(0)).thenReturn(dummyEmail);   }      @Test   public void shouldFetchEmailWhenStarting(       EmailView emailView) {        // WHEN     emailSystem.start();              // THEN     verify(emailView).addEmail(dummyEmail);   } }或者:@RunWith(JukitoRunner.class) public class CalculatorTest {   public static class Module extends JukitoModule {     protected void configureTest() {       bindMany(Calculator.class,           ScientificCalculator.class,           BusinessCalculator.class);       bindManyInstances(AdditionExample.class,            new AdditionExample(1, 1, 2),           new AdditionExample(10, 10, 20),           new AdditionExample(18, 24, 42));     }   }   @Test   public void testAdd(@All Calculator calculator, @All AdditionExample example) {     // WHEN     int result = calculator.add(example.a, example.b);     // THEN     assertEquals(example.expected, result);   } } 标签:Jukito

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值