My code is like below
@Test public void testMyMethod(){ MyClass mc = new MyClass(); String exeVal="sometext some text"; String x=mc.exampleMethod(); // Assertion type 1 Assert.assertEquals(exeVal,x); //Assertion Type 2 Assert.assertTrue(exeVal.equals(x)); } I want to know which is the best approach.
assertEquals()invokes theequals()method on given objects. Use whatever you prefer.assertEqualswill give you clearer feedback, I'd say it is better to use that.