对 assertEquals 的不明确引用
Ambiguous references to assertEquals
days = DayHelper.getInstance().getDays();
Assert.assertNotNull(days);
Assert.assertEquals(5, days.size());
final Day day = days.get(0);
Assert.assertNotNull(day);
Assert.assertEquals("01/10/2018", day.getId());
Assert.assertEquals("Mon", day.getDay());
Assert.assertEquals(1450, day.getQuota()); //Red underlined
Assert.assertEquals(41, day.getWeekno()); //Red underlined
Assert.assertEquals("Inserted duing DayHelperTest", day.getNote());
在 'final day' 块中,三个断言编译没有问题... String
预期和实际 String
来自数据库
红色下划线的两个期望 Integer
并得到 Integer
。
但是,我无法摆脱下面的错误!!!
Error:(56, 19) java: reference to assertEquals is ambiguous both method assertEquals(java.lang.Object,java.lang.Object) in org.junit.Assert and method assertEquals(long,long) in org.junit.Assert match
有人可以帮忙吗。
谢谢。
试试这个:
Assert.assertEquals(1450L, day.getQuota());
Assert.assertEquals(41L, day.getWeekno());
注意到数字前面的 L
了吗?这就是我们指定在 long
值之间进行比较的方式。
当我在 assertEquals
中遇到这样的错误时,这是因为我试图断言从方法返回的 Long
对象等于 long
原始值。
要么两个参数都应该是原始的 long
s
assertEquals(1450L, (long) day.getQuota());
(如果 getQuota()
returns 为空,则有 NullPointerException
的风险,但您的测试无论如何都会失败)
或者两个参数都应该是对象
assertEquals(Long.valueOf(1450), day.getQuota());
days = DayHelper.getInstance().getDays();
Assert.assertNotNull(days);
Assert.assertEquals(5, days.size());
final Day day = days.get(0);
Assert.assertNotNull(day);
Assert.assertEquals("01/10/2018", day.getId());
Assert.assertEquals("Mon", day.getDay());
Assert.assertEquals(1450, day.getQuota()); //Red underlined
Assert.assertEquals(41, day.getWeekno()); //Red underlined
Assert.assertEquals("Inserted duing DayHelperTest", day.getNote());
在 'final day' 块中,三个断言编译没有问题... String
预期和实际 String
来自数据库
红色下划线的两个期望 Integer
并得到 Integer
。
但是,我无法摆脱下面的错误!!!
Error:(56, 19) java: reference to assertEquals is ambiguous both method assertEquals(java.lang.Object,java.lang.Object) in org.junit.Assert and method assertEquals(long,long) in org.junit.Assert match
有人可以帮忙吗。
谢谢。
试试这个:
Assert.assertEquals(1450L, day.getQuota());
Assert.assertEquals(41L, day.getWeekno());
注意到数字前面的 L
了吗?这就是我们指定在 long
值之间进行比较的方式。
当我在 assertEquals
中遇到这样的错误时,这是因为我试图断言从方法返回的 Long
对象等于 long
原始值。
要么两个参数都应该是原始的 long
s
assertEquals(1450L, (long) day.getQuota());
(如果 getQuota()
returns 为空,则有 NullPointerException
的风险,但您的测试无论如何都会失败)
或者两个参数都应该是对象
assertEquals(Long.valueOf(1450), day.getQuota());