简体   繁体   English

如何设置Ant'junit'任务的工作目录?

[英]How do I set the working directory for the Ant 'junit' task?

My Ant build includes a junit task that runs some tests. 我的Ant构建包括一个运行一些测试的junit任务。 In order for the tests to work, the value of the property that specifies the current working directory ( user.dir ) must be changed, but I am unsure how to achieve this. 为了使测试起作用,必须更改指定当前工作目录( user.dir )的属性的值,但我不确定如何实现此目的。

The task in question currently looks like this: 有问题的任务目前看起来像这样:

<junit printsummary="withOutAndErr" fork="true"
           haltonfailure="yes" showoutput="true"
           filtertrace="false" dir="C:/workspace/obp-web">
    <jvmarg value="-Duser.dir=C:/workspace/obp-web"/>

    <classpath>
        <fileset dir="${web.lib.dir}" includes="**/*.jar"/>
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </classpath>    
    <batchtest fork="no" todir="${web.build.dir}/testresults">
        <formatter type="xml"/>
        <zipfileset src="${web.build.dir}/test-obp-web.jar">
            <include name="**/*Test.class"/>
        </zipfileset>           
    </batchtest>
</junit>

Notice that I've tried to use both the "dir" attribute and the "jvmarg" task to change the working directory to C:/workspace/obp-web. 请注意,我尝试使用“dir”属性和“jvmarg”任务将工作目录更改为C:/ workspace / obp-web。 However when I run Ant with verbose output turned on, I see the following output, which indicates that the working dir has not been set correctly: 但是当我运行Ant并打开详细输出时,我看到以下输出,表明工作目录未正确设置:

[junit] dir attribute ignored if running in the same VM 如果在同一个VM中运行,则会忽略[junit] dir属性

[junit] Using System properties {java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=c:\\jdk6\\jre\\bin, java.vm.version=10.0-b23, ant.lib rary.dir=C:\\java\\apache-ant-1.7.0\\lib, java.vm.vendor=Sun Microsystems Inc., java.vendor.url= http://java.sun.com/ , path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=CA, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=Service Pack 1, java.vm.specification.name=Java Virtual Machine Specification, user.dir=c:\\workspace\\obp-ear , java.runtime.version=1.6.0_07-b06, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorse d.dirs=c:\\jdk6\\jre\\lib\\endorsed, os.arch=x86, java.io.tmpdir=C:\\Users\\donal\\AppData\\Local\\Temp\\, line.separator= [junit]使用系统属性 {java.runtime.name = Java(TM)SE运行时环境,sun.boot.library.path = c:\\ jdk6 \\ jre \\ bin,java.vm.version = 10.0-b23,ant。 lib rary.dir = C:\\ java \\ apache-ant-1.7.0 \\ lib,java.vm.vendor = Sun Microsystems Inc.,java.vendor.url = http://java.sun.com/,path 。 separator =;,java.vm.name = Java HotSpot(TM)客户端VM,file.encoding.pkg = sun.io,user.country = CA,sun.java.launcher = SUN_STANDARD,sun.os.patch.level = Service Pack 1,java.vm.specification.name = Java虚拟机规范, user.dir = c:\\ workspace \\ obp-ear ,java.runtime.version = 1.6.0_07-b06,java.awt.graphicsenv = sun。 awt.Win32GraphicsEnvironment,java.endorse d.dirs = c:\\ jdk6 \\ jre \\ lib \\ endorsed,os.arch = x86,java.io.tmpdir = C:\\ Users \\ donal \\ AppData \\ Local \\ Temp \\,line。分离器=

Use the attribute "dir" (must also fork the vm): 使用属性“dir”(还必须分叉vm):

http://ant.apache.org/manual/Tasks/junit.html http://ant.apache.org/manual/Tasks/junit.html

Try using a jvmarg: 尝试使用jvmarg:

<junit fork="yes">
  <jvmarg value="-Duser.dir=somedir"/>
  ...
</junit>

Note that fork must be true on both the junit tag and the batchtest tag as the batchtest tag overrides the value from junit . 请注意,对于junit标记和batchtest标记,fork 必须为true,因为batchtest标记会覆盖junit中的值。 Jvmargs only work if junit forks a new JVM. Jvmargs仅在junit分叉新JVM时才有效。

Have you tried pathelement location? 你尝试过pathelement位置吗? This worked for me. 这对我有用。

  <classpath>
<!-- filesets, etc. -->
<pathelement location="C:/workspace/obp-web" />
  </classpath>

Same problem as you. 和你一样的问题。

I resolved it by making the batchtest fork to true : 我通过将batchtest fork设置为true来解决它:

batchtest fork=" no " .. batchtest fork =“ no ”..

to

batchtest fork=" yes " .. batchtest fork =“ ”..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM