google-compile-testing
我正在编写一个注释处理器,并希望使用and为它编写一些单元测试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 repo 复制了一个简单的测试,并用我的注释处理器替换了相关数据。我正在使用 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>
任何暗示我做错了什么?我找不到与 google dagger2 测试有任何区别(顺便说一下在我的机器上编译)