I've created a SortedList Class, which has a Constructor that takes a java.util.Comparator as an argument.
After running Unit tests on my machine (through eclipse 3.3.0), everything was OK. However, Hudson complaints because it says it can't instantiate my comparator.
Here its my simple test (snippets)
public class SortedListTest {
class strcmp implements Comparator<String>{
public strcmp(){}
public int compare(String s1,String s2){
return s1.compareTo(s2);
}
}
@Test
public void testAdd(){
SortedList<String> list = new SortedList<String>(new strcmp());
}
}
Or an alternative way:
public void testAdd(){
SortedList<String> list = new SortedList<String>(new Comparator<String>(){
public int compare(String s1,String s2){
return s1.compareTo(s2);
}
});
}
The error Hudson shows is
ar.com.lib.SortedListTest$strcmp.initializationError0
Error Message
Test class should have public zero-argument constructor
Stacktrace
java.lang.Exception: Test class should have public zero-argument constructor at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) Caused by: java.lang.NoSuchMethodException: ar.com.lib.SortedListTest$strcmp.() at java.lang.Class.getConstructor0(Class.java:2706) at java.lang.Class.getConstructor(Class.java:1657)
I-ve tried using the @Ignore annotation, but no luck so far. It wont compile when i try
@Ignore class strcmp{}
Any ideas will be appreciated. Thanks in advance.
The problem is that Hudson is seeing strcmp as a test class that it tries to run. The fact that this is an inner class doesn't change that. The Hudson configuration needs to be changed to exclude this class as a test class.
If you can't do that, then make strcmp a public static class with a public noargs constructor and add a test method to it that does nothing (or the ignore tag on the class might work). But it would be much better if you could get the test runner to not pick that class up as a test class at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With