java – JUnit推荐assertTrue()或assertEquals()为String?
发布时间:2020-12-14 16:18:36 所属栏目:Java 来源:网络整理
导读:我的代码如下 @Testpublic 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.equal
我的代码如下
@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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |