Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does surefire ignore test categories for Scala specs2 test when run with maven surefire?
    text
    copied!<p>I have a Scala Specs 2 test that looks as follows:</p> <pre><code>import org.specs2.mutable.Specification import org.junit.runner.RunWith import org.junit.experimental.categories.Category import util.categories.NightlyTestCategory import org.specs2.runner.JUnitRunner import org.junit.Test import org.junit.runners.JUnit4 @RunWith(classOf[JUnitRunner]) class MyTest extends Specification { "My Test" should { "succeed" in { done } } } </code></pre> <p>Note that the above test uses a custom runner JUnitRunner (from Specs2) to execute the test. I use Maven 3 to maintain the project and have configured surefire to only include tests marked with group NightlyTestCategory:</p> <pre><code> &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt; &lt;version&gt;2.15&lt;/version&gt; &lt;configuration&gt; ... &lt;groups&gt;util.categories.NightlyTestCategory&lt;/groups&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <p>When I execute the tests, I expect Maven to not run the above test as it is not annotated with Category NightlyTestCategory. However, Maven does execute the test. The strange thing is that if I turn the test into a regular JUnit test that is executed with JUnit4 runner, Maven will execute this test only if I add Category NightlyTestCategory:</p> <pre><code>@RunWith(classOf[JUnit4]) @Category(Array(classOf[NightlyTestCategory])) class MyTest extends Specification { @Test def test = println("Test") } </code></pre> <p>For me it seems like using the custom Specs2 runner JUnitRunner somehow influences surefire to ignore the groups setting and simply run all the tests it finds. I am looking for a solution that allows me to run the specs2 test with JUnitRunner but at the same time the category should be respected.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload