使用Gradle AspectJ将生产方面编入测试类 [英] Weaving production aspect into test class with Gradle AspectJ

查看:560
本文介绍了使用Gradle AspectJ将生产方面编入测试类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Gradle AspectJ插件将一些生产方面编织成测试Java代码。我预料到这可以与插件一起使用,但显然这并非如此演示:
https://github.com/sedubois/gradle-aspectj-poc/tree/dc44f529831a485fcff8f4889dba8098784dddb4



编织 UnsupportedOperationAspect 转换为 MainSevice (均位于 src / main / java )的作品,但是将相同方面编织成 TestService (在 src / test / java 下) 。



我是Groovy,Gradle和AspectJ的新手,并没有弄清楚是否应该添加一些 testAspectpath 配置或类似的?

EDIT1:似乎不相关,但iajc给出了警告:

...
:compileTestAspect
[ant:iajc] [warning]不正确的classpath:[...] \gradle-aspectj-poc\build\resources\main
...



EDIT2:我天真地将这段代码添加到Gradle依赖关系中:

  ajInpath fileTree(dir:src / test / java)
pathpath fileTree(dir:src / test / java)
testAjInpath fileTree(dir: src / test / java)
testAspectpath fileTree(dir:src / test / java)

没有帮助,第一个测试工作正常,第二个测试失败,如下所示:

.. 。
:compileAspect
[ant:iajc] [warning]构建配置错误:跳过缺少的,空的或已损坏的aspectpath条目:[...] \gradle-aspectj-poc\src\test \java\com\hello\aop\TestService.java
[ant:iajc] [warning]构建配置错误:跳过丢失,空或损坏的inpath项:[...] \gradle -aspectj-poc\src\test\java\com\hello\aop\TestService.java
...
:compileTestAspect
[ant:iajc] [警告]建立配置错误:跳过丢失,时间pty或损坏的纵横比条目:[...] \gradle-aspectj-poc\src\test\java\com\hello\aop\TestService.java
[ant:iajc] [warning]构建配置错误:跳过缺少,空或损坏的inpath项:[...] \gradle-aspectj-poc\src\test\java\com\hello\aop\TestService。 java
[ant:iajc] [warning]错误的classpath:[...] \gradle-aspectj-poc\build\resources\main
...
code>

解决方案

默认情况下,插件不会编写测试类中的主要方面 - 配置选项。您可以使用以下行自己执行此操作:

  testAspectpath sourceSets.main.output 


I am using the Gradle AspectJ plugin to weave some production aspect into test Java code. I would have expected this to work out of the box with the plugin, but apparently that's not the case as demoed here: https://github.com/sedubois/gradle-aspectj-poc/tree/dc44f529831a485fcff8f4889dba8098784dddb4

The weaving of UnsupportedOperationAspect into MainSevice (both under src/main/java) works, but the weaving of this same aspect into TestService (under src/test/java) doesn't.

I am new to Groovy, Gradle and AspectJ and didn't figure out if I should add some testAspectpath configuration or similar?

EDIT1: seems unrelated, but iajc gives a warning:

... :compileTestAspect [ant:iajc] [warning] incorrect classpath: [...]\gradle-aspectj-poc\build\resources\main ...

EDIT2: I naively added this code to the Gradle dependencies:

ajInpath fileTree(dir: "src/test/java")
aspectpath fileTree(dir: "src/test/java")
testAjInpath fileTree(dir: "src/test/java")
testAspectpath fileTree(dir: "src/test/java")

It doesn't help, the first test works and the second one fails as usual, with these new messages:

... :compileAspect [ant:iajc] [warning] build config error: skipping missing, empty or corrupt aspectpath entry: [...]\gradle-aspectj-poc\src\test\java\com\hello\aop\TestService.java [ant:iajc] [warning] build config error: skipping missing, empty or corrupt inpath entry: [...]\gradle-aspectj-poc\src\test\java\com\hello\aop\TestService.java ... :compileTestAspect [ant:iajc] [warning] build config error: skipping missing, empty or corrupt aspectpath entry: [...]\gradle-aspectj-poc\src\test\java\com\hello\aop\TestService.java [ant:iajc] [warning] build config error: skipping missing, empty or corrupt inpath entry: [...]\gradle-aspectj-poc\src\test\java\com\hello\aop\TestService.java [ant:iajc] [warning] incorrect classpath: [...]\gradle-aspectj-poc\build\resources\main ...

解决方案

By default the plugin does not weave the main aspects in the test classes - we simply never made a configuration option for it. You can do this yourself using the following line:

testAspectpath sourceSets.main.output

这篇关于使用Gradle AspectJ将生产方面编入测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆