播放2.1/在运行测试时考虑一个Javaagent [英] Play 2.1 / taking in account a javaagent while running tests
问题描述
我的目标是启动包含在我的 Play 应用中的集成测试.
My goal is to launch my integration tests contained within my Play app.
为此,我曾经通过Intellij启动它们. 这些测试需要Spring AspectJ编织,因此我在Intellij测试配置文件中对此VM参数进行了精确调整:
To do so, I used to launch them through Intellij. Those tests needs Spring aspectJ weaving, thus I precised in my Intellij test conf this VM argument:
-javaagent:/Users/myName/.ivy2/cache/org.springframework/spring-instrument/jars/spring-instrument-3.2.2.RELEASE.jar
整个作品.
现在,我希望能够使用简单的play
命令和test-only
命令来通过命令行启动它们.
Now I want to be able to launch them through command-line using the simple play
command following by test-only
command.
首先,我阅读了 这篇文章介绍了向Play应用添加任何Javaagent的方法.
First I read this post dealing with the way to add any javaagent to Play app.
因此,我像这样修改Play的build
文件,添加了Spring的javaagent:
Thus, I modify my Play's build
file like this, adding the Spring's javaagent:
java ${DEBUG_PARAM} -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M ${JAVA_OPTS} -javaagent:/Users/myName/.ivy2/cache/org.springframework/spring-instrument/jars/spring-instrument-3.2.2.RELEASE.jar -Dfile.encoding=UTF-8 -Dplay.version="${PLAY_VERSION}" -Dsbt.ivy.home=`dirname $0`/../repository -Dplay.home=`dirname $0` -Dsbt.boot.properties=`dirname $0`/sbt/sbt.boot.properties -jar `dirname $0`/sbt/sbt-launch.jar "$@"
但是,我的测试只是失败了..抱怨缺少Spring的AspectJ编织.
但这肯定是逻辑,因为test-only
启动了另一个进程...
However, my test merely fails.. complaining about the missing Spring's aspectJ weaving.
But it's surely logic since test-only
launches another process...
有没有办法让我的测试关心使用javaagent进行AspectJ编织?
Is there a way to make my test care about aspectJ weaving using javaagent?
推荐答案
感谢@Igor Romanov在上面的评论中提供的链接,这是我的解决方案:
Thanks to the link provided by @Igor Romanov in the above comment, here my solution:
val myApp = play.Project(appName, appVersion, appDependencies).settings(
Keys.javaOptions in (Test) +=
"-javaagent:/Users/myName/.ivy2/cache/org.springframework/spring-instrument/jars/spring-instrument-3.2.2.RELEASE.jar",
// code remaining
这允许在处理Spring的Aspectj的类中应用加载时编织.
This allows to apply load-time weaving for class dealing with Spring's aspectj.
整体效果很好:)(已通过SBT 0.12.3,Scala 2.10和Play 2.1进行了测试
The whole works pretty well :) (tested with SBT 0.12.3, Scala 2.10 and Play 2.1)
这篇关于播放2.1/在运行测试时考虑一个Javaagent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!