2017-01-23 82 views
6

我有一个包含多个模块和一个常见父模块的maven项目。在这个项目中,有一些单元测试和Junit一起运行,以及BDD Cucumber集成测试。我想运行两个独立的作业,一个运行所有单元测试,另一个运行BDD /集成测试。为了做到这一点,我已经注解我BDD亚军类有一个Junit的类别标注,像这样:通过Maven运行Junit类别的黄瓜测试

@RunWith(Cucumber.class) 
@CucumberOptions(
       tags = { "@ATagToBeRun", "[email protected]","[email protected]" }, 
       dryRun = false, strict = true, 
       features = "src/test/resources/cucumber/testing", 
       glue = { "com.some.company.test", 
         "com.some.company.another.test"}) 
@Category(value = IntegrationTest.class) 
public class FlowExecutionPojoTest { 
} 

我创建父pom Maven的配置文件,它使用maven-surefire-plugin功能,是为了在过滤试验基地组。这里是我的Maven配置:

 <dependencies> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-java</artifactId> 
      <version>1.2.4</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-junit</artifactId> 
      <version>1.2.4</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-spring</artifactId> 
      <version>1.2.4</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-jvm-deps</artifactId> 
      <version>1.0.5</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <profile> 
     <id>testJewels</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <modules> 
      <module>../my-module</module> 
     </modules> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.19.1</version> 
        <configuration> 
         <groups>com.some.company.IntegrationTest</groups> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 

我希望那是什么,当我运行mvn test -PtestJewels与包含在<groups>标签类别注释的类应该执行。实际上没有任何注释类被执行。

值得注意的一点是,当我使用maven-surefire-plugin版本2.18这个工作,但从版本2.18.1,并没有。按照documentation在页面的底部,有在被继承类关于版本2.18.1但在我的情况下,他们在

+1

你能分享你的pom依赖吗? cucumber-java,cucumber-junit软件包? – eg04lt3r

+0

@ eg04lt3r确定的事情,将其添加到问题 – Jewels

回答

2

是我发现原来有上cucumber-jvm库来修复pull request变化这个具体问题。这个问题是由于以下事实造成的:当Junit基于@Category注释过滤测试运行器类时,它也会检查所有子类。在运行.feature文件的黄瓜测试中,也检查代表.feature文件的所有类(黄瓜在FeatureRunner类的实例中将每个.feature文件转换)。由于FeatureRunner类中不存在注释,因此测试会被过滤掉而不会运行。 (之前版本2.18.1 maven-surefire-plugin没有检查子类的注释,因此这不是一个问题。

解决方法,适用于我上面描述的特定设置,其中所有的BDD测试运行在具体的模块,是覆盖<groups>配置子模块中,像这样:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <configuration> 
       <groups combine.self="override"></groups> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

这显然不是在不同的设置工作,因此,它是相当不幸的是,黄瓜球队还没有合并PR我上面提到