Tôi có một ứng dụng gwt được xây dựng trong Maven, bây giờ tôi đã cố gắng để chạy một thử nghiệm GWT đơn giản như dưới đây:Làm cách nào để sử dụng thử nghiệm maven và jUnit cùng nhau?
public class GwtTestLaughter extends GWTTestCase {
/**
* Specifies a module to use when running this test case. The returned
* module must include the source for this class.
*
* @see com.google.gwt.junit.client.GWTTestCase#getModuleName()
*/
@Override
public String getModuleName() {
return "com.sample.services.joker.laughter.Laughter";
}
/**
* Add as many tests as you like
*/
public void testSimple() {
assertTrue(true);
}
}
và trong file pom.xml, cấu hình gwt-maven-plugin và maven-surefire- Plugin như dưới đây:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<configuration>
<!-- Use the 'war' directory for GWT hosted mode -->
<output>${basedir}/war</output>
<webXml>${basedir}/war/WEB-INF/web.xml</webXml>
<runTarget>index.html</runTarget>
<!-- Make sure the GWT compiler uses Xerces -->
<extraJvmArgs>
-Dgwt.style=DETAILED -Xmx512M -Xss1024k -XX:MaxPermSize=128m -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dlogback.configurationFile=./src/test/resources/logback-test.xml
</extraJvmArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useFile>false</useFile>
<forkMode>once</forkMode>
<argLine>-Xmx128m</argLine>
<systemPropertyVariable>
<property>
<name>log4j.configuration</name>
<value>log4j.properties</value>
</property>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>unit-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test.java</include>
<includes>
<excludes>
<exclude>**/GwtTest*.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>true</skip>
<includes>
<include>**/GwtTest*.java</include>
<includes>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
</execution>
<executions>
</plugin>
Khi tôi chạy 'thử mvn' trong dòng lệnh, tôi có thể thấy chỉ kiểm tra Junit bình thường chạy (một với Tên tệp Test.java), khi tôi chạy 'kiểm tra tích hợp mvn', tôi vẫn thấy tất cả các thử nghiệm, bao gồm kiểm tra Junit bình thường và kiểm tra Gwt (những tên có tên tệp GwtTest .java) chạy.
Câu hỏi 1:
Làm thế nào tôi có thể hoàn toàn loại trừ chạy thử nghiệm Junit bình thường trong thời cho thử nghiệm hội nhập? hoặc điều đó là không thể? Bởi vì trong vòng đời maven mặc định, giai đoạn thử nghiệm được xác định là tồn tại trước khi kiểm thử tích hợp, không có cách nào để bỏ qua giai đoạn thử nghiệm để chạy thử nghiệm tích hợp thuần túy?
Vì tôi trộn lẫn tất cả các mã kiểm tra dưới/kiểm tra thư mục src// java, khi tôi chạy 'mvn tích hợp kiểm tra và quan sát đầu ra trong cửa sổ dòng lệnh, tôi thấy như sau:
[INFO] running com.sample.services.joker.laughter.client.GwtTestLaughter
..
[INFO] Validating newly compiled units
[INFO] [ERROR] Errors in 'file:...src/test/java/com/sample/joker/laughter/client/file1Test.java'..
[INFO] [ERROR] Line 42: No source code is available for type...; did you forget to inherit a required module?
...
Câu hỏi 2:
Tôi không hiểu điều này, kiểm tra gwt là một cách rất đơn giản, tại sao nó sẽ xác nhận một Test.java không liên quan và tìm kiếm mã nguồn của nó. mặc dù cuối cùng xây dựng thành công với kiểm tra được thông qua, làm thế nào tôi có thể thoát khỏi những thông báo lỗi khó chịu?
Có lẽ tôi nên quên plugin gwt-mavin và gắn bó với các bài kiểm tra Juint cổ điển?