[英]JUnit test difference between assertEquals() and Assert.assertEquals()
I made a method to count occurrence of a given character in String. 我制作了一种方法来计算String中给定字符的出现。
public Integer numberOf(String str, Character a){}
I tried to test as normal using: 我尝试使用以下方法进行正常测试:
@Test
public void test1(){
Integer result = oc.numberOf("Lungimirante", 'u');
Assert.assertEquals(1, result);
}
but Eclipse complains it. 但是Eclipse抱怨。
I googled and I found that to test it I needed use: 我用谷歌搜索,发现要测试它,我需要使用:
assertEquals(1, result); //it works correctly
instead of: Assert.assertEquals(1, result);
而不是:
Assert.assertEquals(1, result);
Could you explain me why? 您能解释一下为什么吗? What is the difference?
有什么区别?
You don't provide any details for this: 您没有为此提供任何详细信息:
Eclipse complains it.
Eclipse抱怨它。
I suspect it is an Ambiguous method call
... 我怀疑这是一个
Ambiguous method call
...
... which is caused by there being multiple 'forms' of assertEquals
some of which take int, some long, some Object, some String etc etc. ...是由
assertEquals
多个“形式”引起的,其中的一些形式为int,一些long,一些Object,一些String等。
So, you just need to be explicit about which one you want to use. 因此,您只需要明确说明要使用哪一个即可。 For example, both of the following
assertEquals
calls compile because they are explicit about the type of the expected
and actual
argument: 例如,以下两个
assertEquals
调用均会编译,因为它们对expected
参数和actual
参数的类型都是明确的:
Integer result = oc.numberOf("Lungimirante", 'u');
Assert.assertEquals(new Integer(1), result);
Assert.assertEquals(1, result.intValue());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.