HI, 

I'm wondering if its possible(/and how) to get the gradle test task (from java 
plugin) to run tests using a an aspecj WeavingClassLoader.
In our current build we run a forked java task in ant that invokes ant junit 
(which again is forked per batch).


our current ant test;
<target name="test-junit" depends="check-test-junit-uptodate" 
unless="test.junit.uptodate">
        <mkdir dir="${target.test.reports}"/>
        <property name="test.path" refid="test.path.id"/>
        <java classname="org.apache.tools.ant.Main" fork="yes" dir=".">
            <jvmarg value="-Xmx512m"/>
            <jvmarg value="-XX:MaxPermSize=192m"/>
            <arg value="-buildfile"/>
            <arg value="${common.dir}/build-tests-ltw.xml"/>
            <arg line="-Dbasedir='.'"/>
            <arg line="-Dtest.classpath='${test.path}'"/>
            <arg line="-Dmaven.junit.printSummary='true'"/>
            <arg line="-Dmaven.test.include='**/*TestCase.class'"/>
            <arg line="-Dweaving.class.loader='${weaving.class.loader}'"/>
            <classpath>
                <path location="c:\dev\tools\apache-ant-1.8.1\libs17\ant.jar"/>
                <path 
location="c:\dev\tools\apache-ant-1.8.1\libs17\ant-junit.jar"/>
                <path 
location="c:\dev\tools\apache-ant-1.8.1\libs17\ant-launcher.jar"/>
                <path location="${lib.dir}/junit.jar"/>
            </classpath>
        </java>
        <tstamp/>
        <echo file="${junit.timestamp}">${DSTAMP} - ${TSTAMP}</echo>
    </target>

contents of build-tests-ltw.xml
<target name="test">
        <!-- Defaults. Can be overridden on the command line -->
        <property name="maven.test.include" value="**/*TestCase.class"/>
        <property name="maven.test.exclude" value=""/>
        <property name="weaving.class.loader" 
value="com.telenor.cosmos.system.test.CosmosWeavingURLClassLoader"/>

        <junit printsummary="true" haltonfailure="no" fork="yes" 
forkmode="perBatch">
            <jvmarg 
value="-Djavax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/>
            <jvmarg 
value="-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/>
            <jvmarg value="-Djava.system.class.loader=${weaving.class.loader}"/>
            <jvmarg 
value="-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
            <jvmarg value="-Xmx768m"/>
            <jvmarg value="-XX:MaxPermSize=192m"/>
            <classpath>
                <pathelement path="${java.class.path}"/>
                <pathelement path="${test.classpath}"/>
                <pathelement path="${target.test.aspects}"/>
            </classpath>

            <formatter type="xml"/>

            <batchtest todir="target/test-reports" 
failureproperty="junit.failure">
                <fileset dir="target/test-classes" 
includes="${maven.test.include}" excludes="${maven.test.exclude}"/>
            </batchtest>
        </junit>

        <antcall target="writeJunitIfSet"/>
        <antcall target="writeJunitIfNotSet"/>
    </target>

...never mind the duplication, the important bit is getting gradle to use the 
CosmosWeavingClassLoader (that extends aspectj CosmosWeavingClassLoader).

I tried to simply set 

dependencies {
  compile project(':cosmos-test') // + a range of other dependencies...
  testCompile // various test dependencies
  testRuntime project(':cosmos-test') //this is the project containing the 
CosmosWeavingClassLoader
}

test {
  systemProperties['java.system.class.loader'] = 
'com.telenor.cosmos.system.test.CosmosWeavingURLClassLoaders'
}


However that currently only results in;
"Error occurred during initialization of VM
java.lang.Error: java.lang.ClassNotFoundException: 
com.telenor.cosmos.system.test.CosmosWeavingURLClassLoaders" ...


any tips/hints would be appreciated.


cheers
Magnus



                                          

Reply via email to