Engineering Mind
Engineering Mind

Reputation: 113

Junit on Netbeans doesn't work

I know that netbeans has an existing junit plugin but for some reason it doesn't work properly with my code:

public int Add(String a, String b){
  int x = Integer.parseInt(a);
  int y = Integer.parseInt(b);
  return x + y;
}

Junit test class was generated that contains the following test case:

public void testAdd() {
  System.out.println("Add");
  String a = "2";
  String b = "3";
  TestingProject2016 instance = new TestingProject2016();
  int expResult = 5;
  int result = instance.Add(a, b);
  assertEquals(expResult, result);
}

The junit shows that this test fails saying that there is initialization error, although it should be a success since it returns a correct value based on the code above.

enter image description here

Any idea what went wrong?

Note: that I am using Junit 4. Thanks :)

Upvotes: 0

Views: 680

Answers (1)

Luke Woodward
Luke Woodward

Reputation: 64949

From the comments, the fix was to add the @Test annotation to the test method.

The @Test annotation on a method is used to tell JUnit 4 that that method is a test. You had no such annotations, so JUnit found no tests to run, and hence reported an error message with the text 'no runnable methods'.

Upvotes: 2

Related Questions