我正在编写一个注释处理器,并希望使用google-compile-testing和truth为它编写一些单元测试
所以我想写一个非常简单的单元测试。
import static com.google.common.truth.Truth.assertAbout;
import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
@Test
public void componentOnConcreteClass() {
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.NotAClass",
"package test;",
"",
"import my.annotation.MyAnnotation;",
"",
"@MyAnnotation",
"interface NotAComponent {}");
assertAbout(javaSource()).that(componentFile)
.processedWith(new MyProcessor())
.failsToCompile()
.withErrorContaining("interface");
}因此,基本上,我从谷歌的dagger2回购中复制了一个粘贴的简单测试,并用我的注释处理器替换了相关数据。我使用的是maven,并且使用与dagger2相同的依赖关系:
<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
<version>0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>但我不能编译代码。我想有一个泛型仿冒问题,但不知道问题是什么。
Compilation failure:
[ERROR] ProcessorTest.java:[46,5] method assertAbout in class com.google.common.truth.Truth cannot be applied to given types;
[ERROR] required: com.google.common.truth.SubjectFactory<S,T>
[ERROR] found: com.google.testing.compile.JavaSourceSubjectFactory
[ERROR] reason: no instance(s) of type variable(s) S,T exist so that argument type com.google.testing.compile.JavaSourceSubjectFactory conforms to formal parameter type com.google.common.truth.SubjectFactory<S,T>有没有暗示我做错了什么?我找不到谷歌dagger2测试的任何不同之处(顺便说一句,它在我的机器上编译)
发布于 2015-12-24 07:58:50
神器com.google.testing.compile:compile-testing:0.5 org.truth0:truth:0.15,它是真理的老位置。尝试使用0.6的compile-testing代替。
https://stackoverflow.com/questions/34443445
复制相似问题