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.

2
  • You can have a look here stackoverflow.com/questions/1451496/… Commented Sep 7, 2011 at 13:46
  • If you are using BlockJUnit4ClassRunner (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. Commented Sep 7, 2011 at 14:19

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.