我的代码如下
- @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));
- }
我想知道哪个是最好的方法.
解决方法
类型1是首选,因为您不会匹配时会收到的断言消息.
- org.junit.ComparisonFailure: expected: <[foo]> but was: <[bar]>
VS
- java.lang.AssertionError