首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Truth.assertAbout和JavaSourceSubjectFactory.javaSource()

问Truth.assertAbout和JavaSourceSubjectFactory.javaSource()
EN

Stack Overflow用户
提问于 2015-12-23 20:45:34
回答 1查看 480关注 0票数 4

我正在编写一个注释处理器,并希望使用google-compile-testing和truth为它编写一些单元测试

所以我想写一个非常简单的单元测试。

代码语言:javascript
复制
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相同的依赖关系:

代码语言:javascript
复制
        <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>

但我不能编译代码。我想有一个泛型仿冒问题,但不知道问题是什么。

代码语言:javascript
复制
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测试的任何不同之处(顺便说一句,它在我的机器上编译)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-24 07:58:50

神器com.google.testing.compile:compile-testing:0.5 org.truth0:truth:0.15,它是真理的老位置。尝试使用0.6的compile-testing代替。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34443445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档