1

I have test code as below. test1 passes the test but test2 failed when I expect both to fail. Can anyone please explain why this happens?

@Test(dataProvider="prov")
public void test1(int x, int y){
    System.out.println("x=" + x + ", y=" + y);
    assertEquals(x + y, 3);
}

@Test(dataProvider="prov")
public void test2(int x, int y){
    System.out.println("x=" + x + ", y=" + y);
    assertEquals(x + y, 7);
}

@DataProvider
public Object[][] prov(){
    return new Object[][]{
        {1,2},
        {3,4}
    };
}
tanyehzheng
  • 2,201
  • 1
  • 20
  • 33
  • You've got diagnostics in there - what gets printed? – Jon Skeet Jan 30 '12 at 06:26
  • x=1, y=2 x=3, y=4 x=1, y=2 x=3, y=4 – tanyehzheng Jan 30 '12 at 06:28
  • Okay, so both tests are being executed. I'd expect to see two invocations of each test, one passing and one failing... are you sure you're not just seeing the first invocation of each method within your test runner results? – Jon Skeet Jan 30 '12 at 06:29
  • That's the problem. I expects both method to be invoked twice and since each of the method will have one failed invocation, I expects both method to fail. But in the end I got test1 pass and test2 failed. – tanyehzheng Jan 30 '12 at 06:36
  • What are you running the test in? – Jon Skeet Jan 30 '12 at 07:12
  • I tested using testng-6.2.1 in netbeans 7.1 – tanyehzheng Jan 30 '12 at 07:27
  • I tested it by using testng-6.3.1 in idea 10.5. Both two methods are failure, and there are really two invocations , one success and the other failure. Maybe there are something wrong in your project or just there are something you don't see . – linuxlsx Jan 30 '12 at 07:05
  • 1
    Try running your test on the command line and also use the latest version of TestNG. – Cedric Beust Jan 30 '12 at 18:38

1 Answers1

1

Bingo! This is a netbeans bug. In command line, both tests failed.

Off to report the bug now...

tanyehzheng
  • 2,201
  • 1
  • 20
  • 33