2013-11-21 37 views
0

我试图迁移Ant项目到Maven 3.1。目前,我们有针对每个我们想要测试的环境(服务器)的目标,这些环境对Chrome和Firefox运行相同的一组测试。由于有几个限制,我们无法同时运行两个相同类型的浏览器。如果我设置maven surefire插件一次运行1次测试,结果就会起作用。如果我测试两个线程,最终他们开始失败,因为一次浏览器执行多次,因为Firefox对我们的网站执行速度较慢。Maven的单元测试并发性和资源限制

蚂蚁,测试目标包含此:

<parallel threadCount="2"> 
     <junit fork="yes" printsummary="withOutAndErr" haltonfailure="no"> 
      <formatter type="xml" /> 
      <batchtest fork="true" todir="${junit.output.dir}"> 
       <fileset dir="target/test-classes/" includes="**/TestFirefox.class"> 
       </fileset> 
      </batchtest> 
      <classpath refid="DartSeleniumTest.classpath" /> 
     </junit> 

     <junit fork="yes" printsummary="withOutAndErr" haltonfailure="no"> 
      <formatter type="xml" /> 
      <batchtest fork="yes" todir="${junit.output.dir}"> 
       <fileset dir="target/test-classes/" includes="**/TestChrome.class" /> 
      </batchtest> 
      <classpath refid="DartSeleniumTest.classpath" /> 
     </junit> 
    </parallel> 

我使用antrun插件作为替代万无一失的尝试,但它附带的JUnit 3.x的是否有其他选项可以并行运行测试,但分组?

+0

由于您的测试是为JUnit 4.x编写的,所以很可能JUnit 3.x是一个问题? –

+0

是的,我们有400次测试,当我尝试这种解决方案来看,我宁愿不切换到JUnit的3 –

回答

2

OK - 根据您的意见,您希望能够运行使用Maven插件Antrun 4.x版的JUnit测试,但对JUnit的3.x的依赖

在POM中的插件部分允许您指定依赖,这将覆盖这些插件在默认情况下 - 它POM Reference - plugins

在你的情况描述的,这意味着你将有一个插件,看起来结束像这样:

<plugin> 

    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.7</version> 

    <dependencies> 

    <dependency> 
     <groupId>org.apache.ant</groupId> 
     <artifactId>ant-junit</artifactId> 
     <version>1.8.4</version> 
    </dependency> 

    </dependencies> 

    <executions> 

    <execution> 

     <id>test</id> 
     <phase>test</phase> 

     <configuration> 
     <target> 

      <property name="reports.tests" value="${basedir}/target/ant-test-reports"/> 
      <property name="compile.classpath" refid="maven.compile.classpath"/> 
      <property name="test.classpath" refid="maven.test.classpath"/> 

      <mkdir dir="${reports.tests}"/> 

      <junit printsummary="yes" haltonfailure="yes"> 

      <classpath> 
       <pathelement path="${compile.classpath}"/> 
       <pathelement path="${test.classpath}"/> 
      </classpath> 

      <formatter type="plain"/> 

      <batchtest fork="yes" todir="${reports.tests}"> 

       <fileset dir="${basedir}/src/test/java"> 
       <include name="**/*Test.java"/> 
       </fileset> 

      </batchtest> 

      </junit> 

     </target> 

     </configuration> 

     <goals> 
     <goal>run</goal> 
     </goals> 

    </execution> 

    </executions> 

</plugin> 

你可能会想禁用Surefire插件来阻止它运行测试,以及ANT,它可以这样做:

<plugin> 

    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.16</version> 

    <configuration> 
    <skipTests>true</skipTests> 
    </configuration> 

</plugin> 
+0

,我得到以下错误“之类org.apache.tools.ant.taskdefs.optional.junit。没有找到JUnitTask。“ –

+0

道歉,我把错误的依赖关系。我只是尝试以上(用正确的dependencu)与一个JUnit 4.x的测试,它工作:-) –

+0

谢谢尼克。我能够通过使用ant build.xml而不是内联配置来启动junit任务,但除此之外,这正是我所需要的。 –