加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Truth.assertAbout和JavaSourceSubjectFactory.javaSource()

发布时间:2020-12-15 02:12:09 所属栏目:Java 来源:网络整理
导读:我正在编写一个注释处理器,并希望通过使用google-compile-testing和truth为它编写一些单元测试: 所以我想写一个非常简单的单元测试. import static com.google.common.truth.Truth.assertAbout;import static com.google.testing.compile.JavaSourceSubject
我正在编写一个注释处理器,并希望通过使用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");
  }

所以基本上我从google的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测试的任何区别(顺便说一下,我的机器编译)

解决方法

工件com.google.testing.compile:compile-testing:0.5 depends on org.truth0:truth:0.15,这是真理的 old location.尝试使用版本0.6的编译测试.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读