通过Java系统属性,以蚂蚁测试 [英] Passing java system properties to ant tests

查看:157
本文介绍了通过Java系统属性,以蚂蚁测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有蚂蚁执行与以下code罐子

 <目标名称=start.my.jar描述=开始我罐子>
  <回声消息=启动罐子/>
  < Java的罐子=$ {jars.dir} / $ {} my.stub.jar叉=真DIR =$ {} jars.dir重生=真>
            < sysproperty键=properties.filename值=$ {} BASEDIR /path/path/path/filename.properties/>
        < ARG值=开始/>
    < / JAVA>
< /目标与GT;

罐子里面是一个具有以下code类

 公共静态MyFacade createFacade()抛出FileNotFoundException异常,IOException异常{
    返回createFacade(System.getProperty(properties.filename));
}

然后有配置为这种蚂蚁的测试目标。

 <目标名称=测试依赖=编译,支持描述=执行单元测试>
    < MKDIR DIR =$ {} build.test/>
    < MKDIR DIR =$ {测试classes.dir}/>
    < javac的SRCDIR =$ {} build.testDESTDIR =$ {测试classes.dir}调试=$ {}调试nowarn =$ {} nowarnincludeantruntime =false的德precation =$ {德precation}>
        <类路径REFID =main.classpath/>
    < / javac的>
    < JUnit的printsummary =YEShaltonfailure =YESshowoutput =真DIR =$ {测试classes.dir}叉=真forkmode =perBatchfailureproperty =junit.failureerrorproperty = junit.errorhaltonerror =无>
        < jvmarg值= - Xmx1G/>
        < jvmarg值= - Dcom.sun.management.jmxremote/>        <&类路径GT;
            < pathelement位置=$ {测试classes.dir}/>
            < pathelement位置=$ {} classes.dir/>
            <! -
            对于模块restful_api
             - >
            < pathelement位置=$ {} build.deploy/>
            < pathelement位置=$ {} classes.dir/>
            <文件集DIR =$ {} build.lib>
                <包括姓名=*罐子。/>
            < /文件集>
        < /类路径>
        <格式化TYPE =平​​原/>
        < batchtest叉=YEStodir =$ {} build.test>
            <文件集DIR =$ {} build.test>
                <包括姓名=** / * AllTests.java/>
                <包括姓名=** / * TestCase.java/>
            < /文件集>
        < / batchtest>
    < / JUnit的>
    <失败消息=单元测试失败 - 请检查如果=junit.failure/>
    <失败消息=单元测试错误 - 请勾选如果=junit.error/>
< /目标与GT;

我的这个测试目标模块在测试中未能得到我的start.my.jar目标指定的文件属性。有什么我做错了吗?

 严重:该RuntimeException的无法映射到响应,重新投掷到HTTP容器
[JUnit的]显示java.lang.NullPointerException
[JUnit的]在java.io.File中的<&初始化GT;(File.java:222)
[JUnit的]在com.mycompany.myproduct.sdk.facade.MyFacadeFactory.getInputStream(MyFacadeFactory.java:47)
[JUnit的]在com.mycompany.myproduct.sdk.facade.MyFacadeFactory.loadFacade(MyFacadeFactory.java:43)
[JUnit的]在com.mycompany.myproduct.sdk.facade.MyFacadeFactory.createFacade(MyFacadeFactory.java:32)
[JUnit的]在com.mycompany.myproduct.sdk.facade.MyFacadeFactory.createFacade(MyFacadeFactory.java:28)
[JUnit的]在com.mycompany.myproduct.sdk.resources.impl.TransactionResourceImpl.<init>(TransactionResourceImpl.java:70)
[JUnit的]在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
[JUnit的]在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[JUnit的]在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[JUnit的]在java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[JUnit的]在com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:191)


解决方案

搞怪够了这个工作:

 &LT; jvmarg值= -  Dproperties.filename = $ {BASEDIR} /path/path/path/filename.properties/&GT;

我之前所使用的:

 &LT; sysproperty键=值=/&GT;

从来没有做过

I have ant executing a jar with the following code

  <target name="start.my.jar" description="start my jar">
  <echo message="Starting the jar" />
  <java jar="${jars.dir}/${my.stub.jar}" fork="true" dir="${jars.dir}" spawn="true">
            <sysproperty key="properties.filename" value="${basedir}/path/path/path/filename.properties"/>
        <arg value="start" />
    </java>
</target>

inside the jar there is a class with the following code

public static MyFacade createFacade() throws FileNotFoundException, IOException {
    return createFacade(System.getProperty(properties.filename));
}    

and then there's an ant test goal that is configured as this

 <target name="test" depends="compile, support" description="perform unit tests">
    <mkdir dir="${build.test}" />
    <mkdir dir="${test-classes.dir}" />
    <javac srcdir="${build.test}" destdir="${test-classes.dir}" debug="${debug}" nowarn="${nowarn}" includeantruntime="false" deprecation="${deprecation}">
        <classpath refid="main.classpath" />
    </javac>
    <junit printsummary="yes" haltonfailure="yes" showoutput="true" dir="${test-classes.dir}" fork="true" forkmode="perBatch" failureproperty="junit.failure" errorproperty="junit.error" haltonerror="no">
        <jvmarg value="-Xmx1G" />
        <jvmarg value="-Dcom.sun.management.jmxremote" />

        <classpath>
            <pathelement location="${test-classes.dir}" />
            <pathelement location="${classes.dir}" />
            <!--
            For module restful_api
            -->
            <pathelement location="${build.deploy}" />
            <pathelement location="${classes.dir}" />
            <fileset dir="${build.lib}">
                <include name="*.jar" />
            </fileset>
        </classpath>
        <formatter type="plain" />
        <batchtest fork="yes" todir="${build.test}">
            <fileset dir="${build.test}">
                <include name="**/*AllTests.java" />
                <include name="**/*TestCase.java" />
            </fileset>
        </batchtest>
    </junit>
    <fail message="Unittest failures - please check" if="junit.failure" />
    <fail message="Unittest errors - please check" if="junit.error" />
</target>

My tests in this test target module fail to get the property for the file i specified on the start.my.jar target. Is there anything I'm doing wrong?

SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
[junit] java.lang.NullPointerException
[junit]     at java.io.File.<init>(File.java:222)
[junit]     at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.getInputStream(MyFacadeFactory.java:47)
[junit]     at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.loadFacade(MyFacadeFactory.java:43)
[junit]     at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.createFacade(MyFacadeFactory.java:32)
[junit]     at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.createFacade(MyFacadeFactory.java:28)
[junit]     at com.mycompany.myproduct.sdk.resources.impl.TransactionResourceImpl.<init>(TransactionResourceImpl.java:70)
[junit]     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[junit]     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[junit]     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[junit]     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[junit]     at com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:191)

解决方案

Funny enough this worked:

 <jvmarg value="- Dproperties.filename=${basedir}/path/path/path/filename.properties"/>

the one I used before:

 <sysproperty key="" value=""/>

never worked

这篇关于通过Java系统属性,以蚂蚁测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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