2017-02-22 41 views
2

最終的にJUnit4 @Categoryを使用してテスト自動化を実行しました。 PriorityHigh,PriorityMedium、またはPriorityLowのいずれかにマークされています。その後、プラグインのセクションで使用されてコマンドラインで複数のMavenプロファイルを指定してプロパティをスタックする

<profile> 
    <id>PriorityHigh</id> 
    <properties> 
     <testcase.category>com.categories.PriorityHigh</testcase.category> 
    </properties> 
</profile> 
<profile> 
    <id>PriorityMedium</id> 
    <properties> 
     <testcase.category>com.categories.PriorityMedium</testcase.category> 
    </properties> 
</profile> 
<profile> 
    <id>PriorityLow</id> 
    <properties> 
     <testcase.category>com.categories.PriorityLow</testcase.category> 
    </properties> 
</profile> 

は:私はミディアムとの両方をテストしたいとき

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>${surefire.version}</version> 
    <configuration> 
     <groups>${testcase.category}</groups> 
     <systemPropertyVariables> 
      <automation.driver>${browser.name}</automation.driver> 
     </systemPropertyVariables> 
    </configuration> 
</plugin> 

私の問題がある私は、各プロファイルとして設定している私のpom.xml

ハイ、私が追加/連結した

-P PriorityHigh,PriorityMedium 

しかし、その代わりを指定して、彼らは上書きので、ONL y中テストが実行されます。プロファイルが指定されていない場合は

<testcase.category>com.categories.PriorityHigh,com.categories.PriorityMedium,com.categories.PriorityLow</testcase.category> 

pom.xmlは$ {testcase.category}はプロファイルのみに存在することを不平を言いませんし、デフォルト以来、余分な難易度を追加するには、私はこれを追加する必要がありました。

ので、2つの質問:

  1. プロファイルは、「グループ」ノードで正しくスタックする取得する方法は?
  2. プロファイルが指定されていない場合(すべてのテストを実行する必要があります)、より良い方法です。

答えて

3

一番簡単な方法は、プロファイルを捨て、ちょうどシステムプロパティを使用することです:

その後
<properties> 
    <testcase.category>com.categories.PriorityHigh,com.categories.PriorityLow</testcase.category> 
</properties> 

... 

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.19.1</version> 
    <configuration> 
    <groups>${testcase.category}</groups> 
    ... 
    </configuration> 
</plugin> 

mvn verify -Dtestcase.category=com.categories.PriorityHigh 
# runs PriorityHigh tests 

mvn verify -Dtestcase.category=com.categories.PriorityHigh,com.categories.PriorityLow 
# runs PriorityHigh and PriorityLow tests 

mvn verify 
# runs PriorityHigh and PriorityLow tests 

あなたが完全に指定する必要がしたくない場合Mavenのコマンドラインで修飾クラスのクラス名を使用する場合は、Build Helperプラグインを使用して名前を修飾することができます。

<properties> 
    <testcase.category>PriorityHigh,PriorityLow</testcase.category> 
</properties> 

... 

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <version>3.0.0</version> 
    <executions> 
    <execution> 
     <id>build-fq-testcase-category</id> 
     <goals> 
     <goal>regex-property</goal> 
     </goals> 
     <configuration> 
     <name>fq.testcase.category</name> 
     <regex>([^,]+)</regex> 
     <value>${testcase.category}</value> 
     <replacement>com.categories.$1</replacement> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.19.1</version> 
    <configuration> 
    <groups>${fq.testcase.category}</groups> 
    </configuration> 
</plugin> 
その後

mvn verify -Dtestcase.category=PriorityHigh 
# just run PriorityHigh tests 

mvn verify 
# run PriorityLow and PriorityHigh tests 

# etc. 
+0

ありがとうございました!はるかに簡単な解決策です。私の唯一の不満は、ビルドヘルパープラグインを使用すると、fq.testcase.nameがIDEの値として認識されないため、常にエラーの値が表示されることです。コードはまだコンパイルされ、テストは実行されますが、私のOCDはその名前が赤で好きではありません。 – MivaScott

+1

あなたのIDEを空にするか、値が – ryanp

+0

の ''セクションに ''プロパティを追加して、あなたのIDEを騙すかもしれません。何らかの理由で空白のプロパティを追加すると、ワーキング。つまり、優先度に関係なくすべてのテストを実行します。 – MivaScott

関連する問題