Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Cannot Reproduce
-
2.0 (2.2 plugin)
-
None
-
None
-
None
Description
When inner classes were included, it was done in a way that was too powerful. I believe it is too powerful in the following ways:
It is not name based – it assumes that all inner classes of an included class are test cases.
It does not work on nested classes (non-static classes)
See the test case and stack trace below.
I know people put tests in nested classes, but many nested classes exist for other reasons (simple mock objects, for example). Inner classes do not have no-arg constructors, and so including them includes classes that pretty much by definition will not be runnable.
As things stand, I cannot put a nested (non-static inner) class in a test case. I will get the exception below.
There needs to be some marker for nested test classes. If nothing else, nested classes without a no-arg constructor should be ignored.
But that still makes the inclusion very broad. The default inclusion of top-level classes is much more selective. I would prefer if the default inclusion of nested classes followed the same default naming pattern. But at the very least, please ignore classes without no-arg constructors.
I have been puzzling myself over errors like the following:
java.lang.NoSuchMethodException: com.hyphenhealth.edc.drq.editchecks.queries.compute.TestAThing$Foo.<init>()
at java.lang.Class.getConstructor0(Class.java:2647)
at java.lang.Class.getConstructor(Class.java:1629)
at org.apache.maven.surefire.battery.JUnitBattery.getTestConstructor(JUnitBattery.java:307)
at org.apache.maven.surefire.battery.JUnitBattery.processTestClass(JUnitBattery.java:150)
at org.apache.maven.surefire.battery.JUnitBattery.<init>(JUnitBattery.java:81)
at org.apache.maven.surefire.SurefireUtils.instantiateBattery(SurefireUtils.java:63)
at org.apache.maven.surefire.Surefire.instantiateBatteries(Surefire.java:262)
at org.apache.maven.surefire.Surefire.run(Surefire.java:140)
at org.apache.maven.surefire.Surefire.run(Surefire.java:87)
at org.apache.maven.surefire.Surefire.run(Surefire.java:63)
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.SurefireBooter.main(SurefireBooter.java:785)
RUN ABORTED
java.lang.NoSuchMethodException
Test code:
public class TestAThing {
public class Foo { }
}
Attachments
Issue Links
- is depended upon by
-
SUREFIRE-288 Surefire tries to instantiate nested TestCase classes
- Closed
- relates to
-
SUREFIRE-19 default excludes prevents inner class test cases
- Closed