Maven Surefire

Surefire tries to run JUnit4 tests that contain no @Test annotations

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.4.2
  • Fix Version/s: 2.7
  • Component/s: Junit 4.x support
  • Labels:
    None
  • Complexity:
    Intermediate
  • Testcase included:
    yes
  • Number of attachments :
    2

Description

Similar to SUREFIRE-346 but for JUnit4, Surefire tries to run classes that contain no @Test annotations as tests, resulting in the exception:

java.lang.Exception: No runnable methods
at org.junit.internal.runners.MethodValidator.validateInstanceMethods(MethodValidator.java:32)
at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:43)
at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4ClassRunner.java:36)
at org.junit.internal.runners.JUnit4ClassRunner.<init>(JUnit4ClassRunner.java:27)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.apache.maven.surefire.junit4.JUnit4TestSet.<init>(JUnit4TestSet.java:45)
at org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite.createTestSet(JUnit4DirectoryTestSuite.java:56)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:96)
at org.apache.maven.surefire.Surefire.createSuiteFromDefinition(Surefire.java:209)
at org.apache.maven.surefire.Surefire.run(Surefire.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)

Such classes should be ignored by Surefire.

Issue Links

Activity

Hide
Dan Fabulich added a comment -

I'm marking this won't fix, though I could be convinced otherwise. Forgetting to add @Test annotations is a common error for users upgrading from JUnit 3, and even occasionally for experienced users. Naming a class *Test without making it abstract and without putting any @Test annotations is quite unusual, and probably shouldn't be silently ignored.

Show
Dan Fabulich added a comment - I'm marking this won't fix, though I could be convinced otherwise. Forgetting to add @Test annotations is a common error for users upgrading from JUnit 3, and even occasionally for experienced users. Naming a class *Test without making it abstract and without putting any @Test annotations is quite unusual, and probably shouldn't be silently ignored.
Hide
Mark Hobson added a comment -

This is more to address the situation where mock classes named *Test are not run by Surefire. Similar to JUnit3 where classes that do not extend TestCase are not run by Surefire (SUREFIRE-346), the defining factor of a JUnit4 test case is the occurrence of one or more @Test annotations, hence for consistency Surefire should ignore classes that do not contain any @Test annotations.

This also mirrors the behaviour in Eclipse, whereby:

  • a JUnit3 test case can only be run if it extends TestCase
  • a JUnit4 test case can only be run if it contains one or more @Test annotations

It'd be good to have consistency across Maven and IDEs.

Show
Mark Hobson added a comment - This is more to address the situation where mock classes named *Test are not run by Surefire. Similar to JUnit3 where classes that do not extend TestCase are not run by Surefire (SUREFIRE-346), the defining factor of a JUnit4 test case is the occurrence of one or more @Test annotations, hence for consistency Surefire should ignore classes that do not contain any @Test annotations. This also mirrors the behaviour in Eclipse, whereby:
  • a JUnit3 test case can only be run if it extends TestCase
  • a JUnit4 test case can only be run if it contains one or more @Test annotations
It'd be good to have consistency across Maven and IDEs.
Hide
Gabriele Garuglieri added a comment -

Excuse me i don't understand why you fixed this same problem for Junit 3 (SUREFIRE-346) and you refuse to solve it for Junit 4.
Why you should put a restriction on class names when Junit does not?
As Mark pointed out, don't you think that behavior consistency, given that this request doesn't violate any rule, should be more important than anything else?
Thanks, Gabriele

Show
Gabriele Garuglieri added a comment - Excuse me i don't understand why you fixed this same problem for Junit 3 (SUREFIRE-346) and you refuse to solve it for Junit 4. Why you should put a restriction on class names when Junit does not? As Mark pointed out, don't you think that behavior consistency, given that this request doesn't violate any rule, should be more important than anything else? Thanks, Gabriele
Hide
Gabriele Garuglieri added a comment -

Just to clarify better what i mean, why surefire should try to run a class just because it is named "Tester*" when that class does not extend TestCase nor has any Junit 4 annotation in it and it doesn't even import from any junit.* package?

Note that instead a class named "*Tester" is happily ignored.

It looks like surefire is violating its own rules

Show
Gabriele Garuglieri added a comment - Just to clarify better what i mean, why surefire should try to run a class just because it is named "Tester*" when that class does not extend TestCase nor has any Junit 4 annotation in it and it doesn't even import from any junit.* package? Note that instead a class named "*Tester" is happily ignored. It looks like surefire is violating its own rules
Hide
Michal Borowiecki added a comment -

This is an issue for me too.

"Naming a class *Test without making it abstract and without putting any @Test annotation" does not seam unusual to me.

Mock object are one case.
Another one is starting a new project and creating a test class not having implemented any test methods yet. Having to make it abstract is an unnecessary nuisance. What is worse, you then have to remember to make it non-abstract again once you have written the first test.
Another case is wanting to temporarily disabling tests by annotating them with @Ignore. It is inconsistent that you can do it UNLESS there are no more methods with @Test annotation left in the class in which case the exception is raised.

In the end even if these cases were unusual they are not in any way an error and should not be reported as such and should not break a build.

I hope someone is convinced one day that this should be fixed

Show
Michal Borowiecki added a comment - This is an issue for me too. "Naming a class *Test without making it abstract and without putting any @Test annotation" does not seam unusual to me. Mock object are one case. Another one is starting a new project and creating a test class not having implemented any test methods yet. Having to make it abstract is an unnecessary nuisance. What is worse, you then have to remember to make it non-abstract again once you have written the first test. Another case is wanting to temporarily disabling tests by annotating them with @Ignore. It is inconsistent that you can do it UNLESS there are no more methods with @Test annotation left in the class in which case the exception is raised. In the end even if these cases were unusual they are not in any way an error and should not be reported as such and should not break a build. I hope someone is convinced one day that this should be fixed
Hide
Clint Popetz added a comment -

This blows my mind. Having just switched to maven for builds, it's ridiculous that I now have to come up with a set of naming patterns for tests that have never needed them previously. Blech.

Show
Clint Popetz added a comment - This blows my mind. Having just switched to maven for builds, it's ridiculous that I now have to come up with a set of naming patterns for tests that have never needed them previously. Blech.
Hide
Mark Hobson added a comment -

There seems to be enough dissatisfaction with this issue to warrant reopening it. What do you think Dan, shall we take it to the mailing lists for a vote?

Show
Mark Hobson added a comment - There seems to be enough dissatisfaction with this issue to warrant reopening it. What do you think Dan, shall we take it to the mailing lists for a vote?
Hide
Christoph Kutzinski added a comment -

This has also bitten me more than once. Maven shouldn't get in my way too much and it should definitely NOT dictate how I have to name my test support classes (TestUtils.java anyone?).
I'm in the lucky situation where I started a new project with Maven, so it doesn't hurt too much. But imagine I would migrate an existing project with dozens of "Test*" classes which are no test cases, this would be a blocker to switch to maven.

This behavior should be configurable at least.

Show
Christoph Kutzinski added a comment - This has also bitten me more than once. Maven shouldn't get in my way too much and it should definitely NOT dictate how I have to name my test support classes (TestUtils.java anyone?). I'm in the lucky situation where I started a new project with Maven, so it doesn't hurt too much. But imagine I would migrate an existing project with dozens of "Test*" classes which are no test cases, this would be a blocker to switch to maven. This behavior should be configurable at least.
Hide
Dimitri Alexeev added a comment - - edited

I would also vote for reopening this bug.

Perhaps, this solution would work:

@Ignore @Test
public void ignoredMethod() {...}

while the following one results in "java.lang.Exception: No runnable methods":

//@Ignore @Test
public void ignoredMethod() {...}

Show
Dimitri Alexeev added a comment - - edited I would also vote for reopening this bug. Perhaps, this solution would work: @Ignore @Test public void ignoredMethod() {...} while the following one results in "java.lang.Exception: No runnable methods": //@Ignore @Test public void ignoredMethod() {...}
Hide
Rik Smith added a comment -

In my current project, support classes for testing can also be named like *Test.
I don't see why this is so strange, and why surefire cannot silently ignore this. The class doesn't extend testcase (which is by my knowledge required by JUnit 3) and it does not have any annotations (Isn't this also required for JUnit 4?)

This generates a lot of false failed tests.

Show
Rik Smith added a comment - In my current project, support classes for testing can also be named like *Test. I don't see why this is so strange, and why surefire cannot silently ignore this. The class doesn't extend testcase (which is by my knowledge required by JUnit 3) and it does not have any annotations (Isn't this also required for JUnit 4?) This generates a lot of false failed tests.
Hide
Marius Kruger added a comment -

Please fix this.
I don't think its reasonable to fail if you have non-junit-test-classes coincidently named Test* or *Test.
Use the annotation, that is what it is there for.

Show
Marius Kruger added a comment - Please fix this. I don't think its reasonable to fail if you have non-junit-test-classes coincidently named Test* or *Test. Use the annotation, that is what it is there for.
Hide
Mark Hobson added a comment -

Reopening this bug as there's obvious dissatisfaction with the outcome. Please vote if you'd like to see it fixed.

Show
Mark Hobson added a comment - Reopening this bug as there's obvious dissatisfaction with the outcome. Please vote if you'd like to see it fixed.
Hide
Mark Pollack added a comment -

I just got bit by this behavior and it is very annoying. the rule 'a JUnit4 test case can only be run if it contains one or more @Test annotations' seems to the correct and simple solution to the problem.

Show
Mark Pollack added a comment - I just got bit by this behavior and it is very annoying. the rule 'a JUnit4 test case can only be run if it contains one or more @Test annotations' seems to the correct and simple solution to the problem.
Hide
Antony Stubbs added a comment -

This is an issue with anonymous inner classes in a test class, that themselves do not contain @test's:

initializationError0(x.x.x.x.x.TestHomePage$1)  Time elapsed: 0.002 sec  <<< ERROR!
java.lang.Exception: Test class should have public zero-argument constructor
	at org.junit.internal.runners.MethodValidator.validateNoArgConstructor(MethodValidator.java:56)

NB: TestHomePage is an actual junit, but contains at least one anonymous inner class which is not.

Very annoying... To fix this, I'll have to rename 'test' out of the class name. Ugh.

I also have "TestPages" that are not actually junit tests, but SureFire still tries to run them as junits. Workaround was to put them all inside a package, and exclude it manually.

Show
Antony Stubbs added a comment - This is an issue with anonymous inner classes in a test class, that themselves do not contain @test's:
initializationError0(x.x.x.x.x.TestHomePage$1)  Time elapsed: 0.002 sec  <<< ERROR!
java.lang.Exception: Test class should have public zero-argument constructor
	at org.junit.internal.runners.MethodValidator.validateNoArgConstructor(MethodValidator.java:56)
NB: TestHomePage is an actual junit, but contains at least one anonymous inner class which is not. Very annoying... To fix this, I'll have to rename 'test' out of the class name. Ugh. I also have "TestPages" that are not actually junit tests, but SureFire still tries to run them as junits. Workaround was to put them all inside a package, and exclude it manually.
Hide
Antony Stubbs added a comment -

Oh dear - it only seems to run test classes that are names Test or Test - crap. I thought that was for detecting junit3 tests only. :/ this issue just got worse for me. Seems like surefire can't run my tests then?

Show
Antony Stubbs added a comment - Oh dear - it only seems to run test classes that are names Test or Test - crap. I thought that was for detecting junit3 tests only. :/ this issue just got worse for me. Seems like surefire can't run my tests then?
Hide
Keith Wedinger added a comment -

I would also like to see surefire's JUnit 4.4 support fixed so that it matches what JUnit 4.4 does (i.e. run classes that contain @Test annotations). Currently, surefire requires that the class name contain "Test" in order for the class to be considered a test class. A workaround is to use <includes> and/or <excludes> inside the plugin configuration to include or exclude specific classes.

Show
Keith Wedinger added a comment - I would also like to see surefire's JUnit 4.4 support fixed so that it matches what JUnit 4.4 does (i.e. run classes that contain @Test annotations). Currently, surefire requires that the class name contain "Test" in order for the class to be considered a test class. A workaround is to use <includes> and/or <excludes> inside the plugin configuration to include or exclude specific classes.
Hide
Daniel Spangler added a comment - - edited

We had the same thing happen that @Antony Stubbs had.

x.x.x.x.TestDriveSecurityServiceTest$1.initializationError0 =================
java.lang.Exception: Test class should have public zero-argument constructor

Renaming the class to TDriveSecurityServiceTest solved our problem.

Show
Daniel Spangler added a comment - - edited We had the same thing happen that @Antony Stubbs had. x.x.x.x.TestDriveSecurityServiceTest$1.initializationError0 ================= java.lang.Exception: Test class should have public zero-argument constructor Renaming the class to TDriveSecurityServiceTest solved our problem.
Hide
Tom added a comment -

Hi, I would also like this to be fixed. I do want to name my classes as I wish without them to be executed as tests, especially when I use junit 4 annotations to specify what classes are actual tests or not.
Thank you !
Thomas

Show
Tom added a comment - Hi, I would also like this to be fixed. I do want to name my classes as I wish without them to be executed as tests, especially when I use junit 4 annotations to specify what classes are actual tests or not. Thank you ! Thomas
Hide
Dean Ashby added a comment -

I'm a relative newcomer to Maven and this one bit me too. Seems odd that I should have to rename my class called DomainTestCase to something without Test in it in order to get Maven to process my tests without complaining. This really should be fixed.

Show
Dean Ashby added a comment - I'm a relative newcomer to Maven and this one bit me too. Seems odd that I should have to rename my class called DomainTestCase to something without Test in it in order to get Maven to process my tests without complaining. This really should be fixed.
Hide
Mickaël Leduque added a comment -

It should be fixed. I have classes named Test* that are about some completely different kind of tests (i.e. do not talk about unit testing) that are in /src/main/java (not /src/test) and that surefire tries to run with no reasons.

Show
Mickaël Leduque added a comment - It should be fixed. I have classes named Test* that are about some completely different kind of tests (i.e. do not talk about unit testing) that are in /src/main/java (not /src/test) and that surefire tries to run with no reasons.
Hide
Mark Hobson added a comment -

A good workaround is to add @Ignore to the class that shouldn't be run.

Show
Mark Hobson added a comment - A good workaround is to add @Ignore to the class that shouldn't be run.
Hide
Daniel Triphaus added a comment -

This should be fixed, for me this is no real junit4 support if I need a naming-convention for my classfiles.

Show
Daniel Triphaus added a comment - This should be fixed, for me this is no real junit4 support if I need a naming-convention for my classfiles.
Hide
Ben Hutchison added a comment -

This bug is an embarrassment to Maven. Ignore the JUnit4 standard protocol and instead invent your own undocumented test discovery method! 2 years have passed since this was reported, and its still broken...

Show
Ben Hutchison added a comment - This bug is an embarrassment to Maven. Ignore the JUnit4 standard protocol and instead invent your own undocumented test discovery method! 2 years have passed since this was reported, and its still broken...
Hide
Chris Roark added a comment -

This is one of most annoying bug/feature I have ever come across. How can you go against the grain of Junit, it is like breaking the law. I want to disable all tests in my project and start fixing them one by one by having a Cobertura report that starts from 0 and goes up as we fix them. I took great pain in deleting/commenting the @Test and other annotations and also added a prefix 'skip' to all the test methods. And after all the effort I see this bug and the plugin owner's disgusting behaviour.

Show
Chris Roark added a comment - This is one of most annoying bug/feature I have ever come across. How can you go against the grain of Junit, it is like breaking the law. I want to disable all tests in my project and start fixing them one by one by having a Cobertura report that starts from 0 and goes up as we fix them. I took great pain in deleting/commenting the @Test and other annotations and also added a prefix 'skip' to all the test methods. And after all the effort I see this bug and the plugin owner's disgusting behaviour.
Hide
Mark Hobson added a comment -

This is the second most popular issue for Surefire so we need to resolve it. First step would be for someone to contribute a patch that fixes this behaviour.

Show
Mark Hobson added a comment - This is the second most popular issue for Surefire so we need to resolve it. First step would be for someone to contribute a patch that fixes this behaviour.
Hide
Tom Eugelink added a comment -

I took a quick peek in the source code. The logic that decides what to include is in the surefire-api artifact (maven-surefire-plugin -> surefire-booter -> surefire-api). In the plugin a default filename include pattern (Test*.java, *Test.java, *TestCase.java) is defined and that is handed over to the collectTests() method in the SurefireDirectoryScanner class. This method uses org.codehaus.plexus.util.DirectoryScanner to simply scan for files matching the patterns. There is no checking on extending of TestCase or annotations what so ever.

So.

It would not be too difficult to examine the resulting list of classes for these things. The problem is; the code at this level does not know what the actual test environment is, it just handles files. It has no awareness of JUnit3, JUnit4 or possibly other testers. I have not enough understanding of SureFire at this time.

Show
Tom Eugelink added a comment - I took a quick peek in the source code. The logic that decides what to include is in the surefire-api artifact (maven-surefire-plugin -> surefire-booter -> surefire-api). In the plugin a default filename include pattern (Test*.java, *Test.java, *TestCase.java) is defined and that is handed over to the collectTests() method in the SurefireDirectoryScanner class. This method uses org.codehaus.plexus.util.DirectoryScanner to simply scan for files matching the patterns. There is no checking on extending of TestCase or annotations what so ever. So. It would not be too difficult to examine the resulting list of classes for these things. The problem is; the code at this level does not know what the actual test environment is, it just handles files. It has no awareness of JUnit3, JUnit4 or possibly other testers. I have not enough understanding of SureFire at this time.
Hide
Tom Eugelink added a comment -

Ok. I figured it out; in surefire-providers there are classes for different testrunners. A.o. there is a JUnit4DirectoryTestSuite which extends and heavily relies on AbstractDirectoryTestSuite which uses the directory scanner. This class should get additional code to filter the resulting classes on the @Test annotation. Likewise there is a JUnit 3 class which should filter on "extends TestCase".

I'll see what I can do.

Show
Tom Eugelink added a comment - Ok. I figured it out; in surefire-providers there are classes for different testrunners. A.o. there is a JUnit4DirectoryTestSuite which extends and heavily relies on AbstractDirectoryTestSuite which uses the directory scanner. This class should get additional code to filter the resulting classes on the @Test annotation. Likewise there is a JUnit 3 class which should filter on "extends TestCase". I'll see what I can do.
Hide
Tom Eugelink added a comment -

Oh my, that was easy. JUnit4DirectoryTestSuite has a method that actually creates the test runner and it is allowed to return null. So all that needs to be done is check for a method with the @Test annotation. If not found, return null.

Here it is:

protected SurefireTestSet createTestSet( Class testClass, ClassLoader classLoader )
throws TestSetFailedException
{
// this is JUnit4: check to see if there are any methods with a @Test annotations
boolean lTestFound = false;
for (Method lMethod : testClass.getDeclaredMethods())
{
for (Annotation lAnnotation : lMethod.getAnnotations())
{
if (org.junit.Test.class.isAssignableFrom( lAnnotation.annotationType() ))

{ lTestFound = true; break; }

}
}
// if not test found, simply return null
if (lTestFound == false) return null;

// create the testset
return new JUnit4TestSet( testClass );
}

Show
Tom Eugelink added a comment - Oh my, that was easy. JUnit4DirectoryTestSuite has a method that actually creates the test runner and it is allowed to return null. So all that needs to be done is check for a method with the @Test annotation. If not found, return null. Here it is: protected SurefireTestSet createTestSet( Class testClass, ClassLoader classLoader ) throws TestSetFailedException { // this is JUnit4: check to see if there are any methods with a @Test annotations boolean lTestFound = false; for (Method lMethod : testClass.getDeclaredMethods()) { for (Annotation lAnnotation : lMethod.getAnnotations()) { if (org.junit.Test.class.isAssignableFrom( lAnnotation.annotationType() )) { lTestFound = true; break; } } } // if not test found, simply return null if (lTestFound == false) return null; // create the testset return new JUnit4TestSet( testClass ); }
Hide
Kristian Rosenvold added a comment - - edited

Please note that there is a solution to this issue already:

Surefire contains three different Junit providers, 3.x, 4.x and the (parallel) 4.7+ provider.

The 4.7 provider only runs valid junit tests, and it is possible to force the use of this provider even for serial runs, using this (somewhat exotic) configuration setting: <parallel>none</parallel>. As long as junit 4.7+ is used, this will only run proper junit tests.

Please note that due to a few bugs in the 2.5 junit 4.7 provider, it is probably wise to test this with 2.6-SNAPSHOT or better.

Show
Kristian Rosenvold added a comment - - edited Please note that there is a solution to this issue already: Surefire contains three different Junit providers, 3.x, 4.x and the (parallel) 4.7+ provider. The 4.7 provider only runs valid junit tests, and it is possible to force the use of this provider even for serial runs, using this (somewhat exotic) configuration setting: <parallel>none</parallel>. As long as junit 4.7+ is used, this will only run proper junit tests. Please note that due to a few bugs in the 2.5 junit 4.7 provider, it is probably wise to test this with 2.6-SNAPSHOT or better.
Hide
Tom Eugelink added a comment -

The fixed source for JUnit4.

Show
Tom Eugelink added a comment - The fixed source for JUnit4.
Hide
Tom Eugelink added a comment -

IMHO adding those 6 lines of code to the JUnit4 provider is a better solution that the exotic configuration.

Show
Tom Eugelink added a comment - IMHO adding those 6 lines of code to the JUnit4 provider is a better solution that the exotic configuration.
Hide
Kristian Rosenvold added a comment -

Thanks for the patch, Tom.

As can be seen from several of the comments to this issue, there is the problem that this bug has been around long enough to become a feature (pardon the pun). I also know from experience that this "feature" is used by quite a lot of projects.

I believe that any patch to this issue will need to include one or more of the following features:
A) Solve the issue by making the provider-switch more explicit (i.e. leave 4.x provider as-is)
B) Solve 4.x problem more or less as you suggest, but provide log warnings about classes that will not be run any more due to behavior change. While this initially may seem like a nice fix, the problem is that the message will have to be more or less permanently in place - which means we'll be nagging users indefinitely due to what is basically a bug.
C) Make some kind of "strictJunit4classscanning" attribute on surefire plugin that allows the correct behavior to be turned on/off.

I'm sure there's may be other ways to fix this, but I think the fix (in one way or another) needs to respect that it's become somewhat of a "feature".

There also needs to be an integration test for whatever fix is chosen, after all it's a test framework

Show
Kristian Rosenvold added a comment - Thanks for the patch, Tom. As can be seen from several of the comments to this issue, there is the problem that this bug has been around long enough to become a feature (pardon the pun). I also know from experience that this "feature" is used by quite a lot of projects. I believe that any patch to this issue will need to include one or more of the following features: A) Solve the issue by making the provider-switch more explicit (i.e. leave 4.x provider as-is) B) Solve 4.x problem more or less as you suggest, but provide log warnings about classes that will not be run any more due to behavior change. While this initially may seem like a nice fix, the problem is that the message will have to be more or less permanently in place - which means we'll be nagging users indefinitely due to what is basically a bug. C) Make some kind of "strictJunit4classscanning" attribute on surefire plugin that allows the correct behavior to be turned on/off. I'm sure there's may be other ways to fix this, but I think the fix (in one way or another) needs to respect that it's become somewhat of a "feature". There also needs to be an integration test for whatever fix is chosen, after all it's a test framework
Hide
Arseniy Alekseyev added a comment -

Wow, I totally missed the discussion here. Please see my comment and patch at SUREFIRE-535.
I think this must be fixed. I can't see a use case when skipping a class without test methods would cause problems. Kristian, could you please elaborate on this? Why would anyone want the test without test methods to fail?

Show
Arseniy Alekseyev added a comment - Wow, I totally missed the discussion here. Please see my comment and patch at SUREFIRE-535. I think this must be fixed. I can't see a use case when skipping a class without test methods would cause problems. Kristian, could you please elaborate on this? Why would anyone want the test without test methods to fail?
Hide
Kristian Rosenvold added a comment -

I will fix this issue for 2.7 as follows:

  • Impelement the correct behaviour.
  • Adda -Dsurefire.upgrade=true system property that can be run when upgrading, so that users will have warning if their project contains testcases that will not be run anymore (this is the reason why this issue is a bit hard to fix).
  • Include a warning to run (at least once) with this flag when upgrading in release notes.
Show
Kristian Rosenvold added a comment - I will fix this issue for 2.7 as follows:
  • Impelement the correct behaviour.
  • Adda -Dsurefire.upgrade=true system property that can be run when upgrading, so that users will have warning if their project contains testcases that will not be run anymore (this is the reason why this issue is a bit hard to fix).
  • Include a warning to run (at least once) with this flag when upgrading in release notes.
Hide
Kristian Rosenvold added a comment -

Fixed in r1033896. Users upgrading to this version of the plugin should run mvn -Dsurefire.junit4.upgradecheck=true install at least once to verify that they don't have any tests that will be ignored by the new plugin version.

Show
Kristian Rosenvold added a comment - Fixed in r1033896. Users upgrading to this version of the plugin should run mvn -Dsurefire.junit4.upgradecheck=true install at least once to verify that they don't have any tests that will be ignored by the new plugin version.
Hide
Arseniy Alekseyev added a comment - - edited

Kristian, thank you for fixing this.

However, I think I've found a bug that could lead to more serious consequences than we have thought of.
When checking 'value' parameter for @RunWith attribute
instead of "if ( suite.isAssignableFrom( value ) )"
it should be "if ( runner.isAssignableFrom( value ) )"
or better yet "if ( true )".

As it is now, classes with custom runners, or even with a standard Theories runner could be ignored. Should I create a new issue with a test?

Show
Arseniy Alekseyev added a comment - - edited Kristian, thank you for fixing this. However, I think I've found a bug that could lead to more serious consequences than we have thought of. When checking 'value' parameter for @RunWith attribute instead of "if ( suite.isAssignableFrom( value ) )" it should be "if ( runner.isAssignableFrom( value ) )" or better yet "if ( true )". As it is now, classes with custom runners, or even with a standard Theories runner could be ignored. Should I create a new issue with a test?
Hide
Kristian Rosenvold added a comment -

That's really good catch and a nice simplification ! r1033985 just scans for the presence of @RunWith, testcases updated.

Show
Kristian Rosenvold added a comment - That's really good catch and a nice simplification ! r1033985 just scans for the presence of @RunWith, testcases updated.

People

Vote (40)
Watch (30)

Dates

  • Created:
    Updated:
    Resolved: