【发布时间】:2014-06-15 02:25:22
【问题描述】:
我有一个在 Eclipse 中完美运行但在 Gradle 中失败的测试。我不确定出了什么问题。我在 Eclipse 中使用 Java 8。
提示:
E:\Files\Source\Workspace-Eclipse2\project\src\test\java\com\project\core\domain\TeamUnitTest.java:31: error: no sui
table method found for assertThat(List<User>,Matcher<Collection<Object>>)
assertThat(team.getUsers(), empty());
^
method Assert.<T#1>assertThat(T#1,Matcher<? super T#1>) is not applicable
(actual argument Matcher<Collection<Object>> cannot be converted to Matcher<? super List<User>> by method invocati
on conversion)
method Assert.<T#2>assertThat(String,T#2,Matcher<? super T#2>) is not applicable
(cannot instantiate from arguments because actual and formal argument lists differ in length)
where T#1,T#2 are type-variables:
T#1 extends Object declared in method <T#1>assertThat(T#1,Matcher<? super T#1>)
T#2 extends Object declared in method <T#2>assertThat(String,T#2,Matcher<? super T#2>)
E:\Files\Source\Workspace-Eclipse2\project\src\test\java\com\project\core\domain\TeamUnitTest.java:51: error: no sui
table method found for assertThat(List<User>,Matcher<Collection<Object>>)
assertThat(team.getUsers(), empty());
^
method Assert.<T#1>assertThat(T#1,Matcher<? super T#1>) is not applicable
(actual argument Matcher<Collection<Object>> cannot be converted to Matcher<? super List<User>> by method invocati
on conversion)
method Assert.<T#2>assertThat(String,T#2,Matcher<? super T#2>) is not applicable
(cannot instantiate from arguments because actual and formal argument lists differ in length)
where T#1,T#2 are type-variables:
T#1 extends Object declared in method <T#1>assertThat(T#1,Matcher<? super T#1>)
T#2 extends Object declared in method <T#2>assertThat(String,T#2,Matcher<? super T#2>)
2 errors
:compileTestJava FAILED
测试代码:
assertThat(team.getUsers(), empty());
【问题讨论】:
-
Gradle 构建可能是使用不喜欢此代码的早期 Java 版本编译的。查看
gradle -v显示的是哪个JVM版本。 -
@PeterNiederwieser 我会试试这个。
-
向 Hamcrest 1.3 添加显式依赖并使用 JUnit 4.11。