2011-08-04 5 views
9

たぶん誰かが私を助けることができる私はMavenのと私のテストを実行すると、私は、私は私の最初のGWTのユニットテストを書くことをしようとしているが、ここで問題がありますこのエラーが出る:GWTテストエラーNoClassDefFoundErrorが:COM /グーグル/ GWTの/ dev/CFG /条件

> java.lang.NoClassDefFoundError: com/google/gwt/dev/cfg/Condition  at 
> com.google.gwt.junit.client.GWTTestCase.createStrategy(GWTTestCase.java:340) 
> at 
> com.google.gwt.junit.client.GWTTestCase.getStrategy(GWTTestCase.java:257) 
> at 
> com.google.gwt.junit.client.GWTTestCase.getSyntheticModuleName(GWTTestCase.java:275) 
> at 
> com.google.gwt.junit.client.GWTTestCase.setName(GWTTestCase.java:321) 
> at junit.framework.TestSuite.createTest(TestSuite.java:63) at 
> junit.framework.TestSuite.addTestMethod(TestSuite.java:283) at 
> junit.framework.TestSuite.<init>(TestSuite.java:146) at 
> org.junit.internal.runners.JUnit38ClassRunner.<init>(JUnit38ClassRunner.java:71) 
> at 
> org.junit.internal.builders.JUnit3Builder.runnerForClass(JUnit3Builder.java:14) 
> at 
> org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) 
> at 
> org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29) 
> at 
> org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) 
> at 
> org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24) 
> at 
> org.apache.maven.surefire.junit4.JUnit4TestSet.<init>(JUnit4TestSet.java:45) 
> at 
> org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite.createTestSet(JUnit4DirectoryTestSuite.java:56) 
> at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:96) 
> at 
> org.apache.maven.surefire.Surefire.createSuiteFromDefinition(Surefire.java:209) 
> at org.apache.maven.surefire.Surefire.run(Surefire.java:156) at 
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
> at java.lang.reflect.Method.invoke(Method.java:601)  at 
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345) 
> at 
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009) 
> Caused by: java.lang.ClassNotFoundException: 
> com.google.gwt.dev.cfg.Condition at 
> java.net.URLClassLoader$1.run(URLClassLoader.java:366) at 
> java.net.URLClassLoader$1.run(URLClassLoader.java:355) at 
> java.security.AccessController.doPrivileged(Native Method) at 
> java.net.URLClassLoader.findClass(URLClassLoader.java:354) at 
> java.lang.ClassLoader.loadClass(ClassLoader.java:423)  at 
> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)  at 
> java.lang.ClassLoader.loadClass(ClassLoader.java:356) 

は、ここに私のテストケースです:

public class TelekanalServiceImplTest extends GWTTestCase { 

    @Override 
    public String getModuleName() { 
     // TODO Auto-generated method stub 
     return "com.karq.tvkava.tvkavaJUnit"; 
    } 



    public void testTelekanalService(){ 
     // Create the service that we will test. 
     TelekanalServiceAsync telekanalService = GWT.create(TelekanalService.class); 
     ServiceDefTarget target = (ServiceDefTarget) telekanalService; 
     target.setServiceEntryPoint(GWT.getModuleBaseURL() + "tvkava/telekanalService"); 

     // Since RPC calls are asynchronous, we will need to wait for a response 
     // after this test method returns. This line tells the test runner to wait 
     // up to 10 seconds before timing out. 
     delayTestFinish(10000); 
     //Test data 
     Telekanal telekanal = new Telekanal(); 
     telekanal.setNimetus("test"); 
     telekanal.setKirjeldus("see on test"); 
     // Send a request to the server. 
     telekanalService.saveOrUpdateTelekanal(telekanal, new AsyncCallback<Void>() { 
      public void onFailure(Throwable caught) { 
      // The request resulted in an unexpected error. 
      fail("Request failure: " + caught.getMessage()); 
      } 

      public void onSuccess(Void result) { 
      // Verify that the response is correct. 
      boolean isSaved = true; 
      assertTrue(isSaved); 
      // Now that we have received a response, we need to tell the test runner 
      // that the test is complete. You must call finishTest() after an 
      // asynchronous test finishes successfully, or the test will time out. 
      finishTest(); 
      } 
     }); 
    } 

} 

そしてcom.karq.tvkavaに私はtvKavaJUnit.gwt.xml

<?xml version="1.0" encoding="UTF-8"?> 
<module> 
    <!-- Inherit our applications main module.      --> 
    <inherits name='com.karq.tvkava.tvkava'/> 

    <!-- Specify the path to any remote services.     --> 
    <servlet path="/tvkava/telekanalService" class="com.karq.tvkava.server.services.TelekanalServiceImpl" /> 

</module> 
と呼ばれるモジュールのファイルを持っています

そしてofcourseの私はcom.karq.tvkavaでメインモジュールを持っており、その

<?xml version="1.0" encoding="UTF-8"?> 
<module rename-to='tvkava'> 
    <!-- Inherit the core Web Toolkit stuff.      --> 
    <inherits name='com.google.gwt.user.User'/> 

    <!-- Inherit the default GWT style sheet. You can change  --> 
    <!-- the theme of your GWT application by uncommenting   --> 
    <!-- any one of the following lines.       --> 
    <inherits name='com.google.gwt.user.theme.standard.Standard'/> 
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> 
    <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>  --> 

    <!-- Other module inherits          --> 
<inherits name='net.sf.gilead.Gilead4Gwt'/> 
<source path='client/service' /> 
    <source path='shared'/> 
    <!-- Specify the app entry point class.       --> 
    <entry-point class='com.karq.tvkava.client.tvkava'/> 

    <!-- Specify the paths for translatable code     --> 
    <source path='client'/> 
    <source path='shared'/> 

</module> 
+0

あなたはこの問題を解決しましたか? –

答えて

4

tvkava.gwt.xmlと呼ばれるクラスパス上gwt-user.jargwt-dev.jarの両方を持っていますか?

+0

はい、私はクラスパスにそれらを持っています。 – karq

10

私は正しい結果を出力し、テストの失敗がある場合、ビルドに失敗し、シュアは私のGWTのテストとシームレスに動作するように得ることができました。私のPOMでは、私は、シュアはそうのように設定持っている:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.12</version> 
    <configuration> 
     <additionalClasspathElements> 
      <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement> 
      <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement> 
     </additionalClasspathElements> 
     <useSystemClassLoader>true</useSystemClassLoader> 
     <useManifestOnlyJar>false</useManifestOnlyJar> 
     <forkMode>always</forkMode> 
     <systemProperties> 
      <property> 
       <name>gwt.args</name> 
       <value>-out www-test</value> 
      </property> 
     </systemProperties> 
    </configuration> 
</plugin> 

あなたは変数project.build.sourceDirectoryproject.build.testSourceDirectoryを定義する必要があります。私にとっては、彼らは<project-name>/src/main/java<project-name>/src/test/javaのようなものです。

は私もgwt-devへの依存に追加する必要がありました:

<dependency> 
    <groupId>com.google.gwt</groupId> 
    <artifactId>gwt-dev</artifactId> 
    <version>2.4.0</version> 
    <scope>provided</scope> 
</dependency> 
5

私は、同じ正確なスタックトレースを持っていたし、

<dependency> 
    <groupId>com.google.gwt</groupId> 
    <artifactId>gwt-dev</artifactId> 
    <version>${gwtVersion}</version> 
    <scope>test</scope> 
</dependency> 

を追加すると、それを修正しました。

1

あなたがSureFireでGWTTestをJUnitテストとして実行した場合、このエラーメッセージが表示されます。 SureFireはGWTコードと何をするべきかを知らないので、このエラーが発生します。

特定のパターンですべてのテストを無視するようにSureFireに指示することをお勧めします。私はすべてのGWTテストに「SomethingGwtTest.java」という名前を付けます。このようにしてSureFireはそれらを無視し、gwt-maven-pluginのGWTテストランナーがそれらを選択して適切に実行します。

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
     <excludes> 
      <exclude>**/*GwtTest.java</exclude> 
     </excludes> 
    </configuration> 
</plugin