4

I have to run junit test from command line and one of the guy in the team created junit classes like below:

public Test extends TestCore
{
   String some;

   public Test(String some)
   {
      this.some = some;
   }
//some test here
}

this work from the eclipse but doesn't from command line. The result of execution this kind of file gave me error like below:

Test class should have exactly one public zero-argument constructor.

Anyone could help me?

Cheers Jaroslaw.

Adam Matan
  • 128,757
  • 147
  • 397
  • 562
Jarolsaw
  • 41
  • 1
  • 2
  • You can have a look here http://stackoverflow.com/questions/1451496/does-junit4-testclasses-require-a-public-no-arg-constructor –  Sep 07 '11 at 13:46
  • If you are using [`BlockJUnit4ClassRunner`](http://kentbeck.github.com/junit/javadoc/latest/org/junit/runners/BlockJUnit4ClassRunner.html#createTest%28%29) (in any form) to run your tests, then you will need a no-arg constructor for your test class; Eclipse doesn't use this TestRunner in its JUnit4 test runner. You might want to re-look at why you need a constructor with arguments for your test classes in the first place. – Vineet Reynolds Sep 07 '11 at 14:19

1 Answers1

2

Eclipse uses a different testrunner. Maybe the parameterized constructors are caused by TestCore being a parameterized test, e.g. like this:

@RunWith(Parameterized.class)
public class TestCore {
  String someThatWillBeHidden;

  public TestCore(String some) {
    this.someThatWillBeHidden = some;
  }

  @Parameters
  public static List<Object[]> data() {
    Object[][] data = new Object[][] { {"Hello"}, {" "}, {"world"}}; 
    return Arrays.asList(data);
  }

//some test here

}

So which version of junit are you using?

DaveFar
  • 7,078
  • 4
  • 50
  • 90