-2

I have this Java code:

public class Calc {
    public int quotient(int a, int b){
        return a/b;
    }
}

and TestNG unit test for this method:

@Test ()
public void testingMethod3() {
    Assert.assertEquals(0, calc.quotient(5,0));
}

On my work computer I successfully get

java.lang.ArithmeticException: / by zero

message, as expected.

But when my colleague runs this test on home computer, then mentioned exception is not throwing and test passes.

How this magic could occur?

P.S. Environment OS: Windows 10 TestNG version: 6.13.1 Java version: 8 (don't know exact build version)

P.P.S. Deletion of target folder and rebuilding of the project was that very helpful solution. Seem like IDE cashed old project sources, and didn't flush them after changes in the code.

Sančiezz
  • 81
  • 2
  • 11

1 Answers1

1

In the past, I experienced something like yours. Because different JDK compile environment and/or JRE runtime environment. And need check the different of version of TestNG.

check by add few line of code to print Java properties.

Properties p = System.getProperties();
Enumeration keys = p.keys();
while (keys.hasMoreElements()) {
    String key = (String)keys.nextElement();
    String value = (String)p.get(key);
    System.out.println(key + ": " + value);
}

then comparing

Vy Do
  • 46,709
  • 59
  • 215
  • 313