使用编译测试对注释处理器进行单元测试时的AssertionError

时间:2015-09-04 09:36:11

标签: java unit-testing annotation-processing

Google的compile-testing是单元测试注释处理器的绝佳工具。不幸的是,我目前面临以下错误:

java.lang.AssertionError: 
An expected source declared one or more top-level types that were not present.

Expected top-level types: <[test.LocalStorage]>
Declared by expected file: <LocalStorageImpl.java>

The top-level types that were present are as follows: 

- [test.LocalStorageImpl] in </SOURCE_OUTPUT/test/LocalStorageImpl.java>

我的处理器生成带注释的界面的实现。因此生成的代码依赖于接口(class LocalStorageImpl implements LocalStorage)。

当我尝试使用

验证生成的代码时
    JavaFileObject source = /* interface definition */
    JavaFileObject expected_source = /* the generated implementation */

    assertAbout(javaSource()).that(source)
    .processedWith(new MyProcessor())
    .compilesWithoutError()
    .and()
    .generatesSources(expectedSource);

... generatesSource导致错误。正如错误消息所述,它无法解析接口定义。

所以我的问题是如何编译或编写source中定义的接口的源文件,以便generatesSources()识别它?

0 个答案:

没有答案