Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring与Aspectj加载时间交织,方面未在集成测试中执行_Spring_Aspectj_Junit4 - Fatal编程技术网

Spring与Aspectj加载时间交织,方面未在集成测试中执行

Spring与Aspectj加载时间交织,方面未在集成测试中执行,spring,aspectj,junit4,Spring,Aspectj,Junit4,因此,我试图对现有代码进行一些集成测试,并需要模拟一个私有方法返回。 因此,我想我应该尝试一下AspectJ LTW,并将建议编织到私有方法中,让建议执行切入点忽略响应,然后发送我自己的响应 我通过jUnit测试来执行这个。我正在分叉执行,以便传入javaagent <target name="test-integration" depends="compile-test"> <echo message="============================

因此,我试图对现有代码进行一些集成测试,并需要模拟一个私有方法返回。 因此,我想我应该尝试一下AspectJ LTW,并将建议编织到私有方法中,让建议执行切入点忽略响应,然后发送我自己的响应

我通过jUnit测试来执行这个。我正在分叉执行,以便传入javaagent

    <target name="test-integration" depends="compile-test">
    <echo message="========================================" />
    <echo message=" Executing target test-integration" />
    <echo message="========================================" />
    <delete dir="${test.report.dir}" failonerror="false" />
    <mkdir dir="${test.report.dir}" />
    <junit printsummary="yes" fork="yes" haltonfailure="yes" haltonerror="yes" showoutput="yes" >
        <jvmarg value="-javaagent:${spring.instrument.jar}" />
        <classpath>
            <pathelement location="${classes.test.dir}" />
            <pathelement location="${classes.dir}" />
            <path refid="test.run.classpath" />
            <path refid="compile.classpath" />
            <pathelement location="${test.resources}" />
        </classpath>
        <formatter type="plain" />
        <batchtest fork="yes" todir="${test.report.dir}">
            <fileset dir="${classes.test.dir}">
                <include name="com/test/integrationtest/*IntegrationTest*" />
                <exclude name="**/*$*" />
            </fileset>
        </batchtest>
    </junit>
</target>
}

正如你所看到的,我选择了一个特定的类来编织建议,并选择了它的私有方法来模拟响应

最后但并非最不重要的一点是,我补充道

<context:load-time-weaver/>

加载到ClassPathXmlApplicationContext中的第一个上下文文件

有人有什么想法吗

多亏了添加

            <!--jvmarg value="-Dorg.aspectj.weaver.showWeaveInfo=true" />
        <jvmarg value="-Daj.weaving.verbose=true" />
        <jvmarg value="-Dorg.aspectj.tracing.enabled=true" />
        <jvmarg value="-Dorg.aspectj.tracing.factory=default" /-->

对于ant junit配置和更多的注销,aspectJ配置正在工作,但看起来Spring实际上也需要编织Aspect,以便能够访问它。在我将MockMethodReturnIntercepter包添加到weaver之前,我一直在获取aspectOf()方法的MethodNotFound异常

<include within="com.test.integrationtest.*" />

这样做之后,一切都很好。显然这是Spring3.x的新功能

            <!--jvmarg value="-Dorg.aspectj.weaver.showWeaveInfo=true" />
        <jvmarg value="-Daj.weaving.verbose=true" />
        <jvmarg value="-Dorg.aspectj.tracing.enabled=true" />
        <jvmarg value="-Dorg.aspectj.tracing.factory=default" /-->
<include within="com.test.integrationtest.*" />