3

我保证,我读过: http: //netbeans.org/kb/articles/freeform-config.html

我有一个 java 自由格式项目,我想修改它以在Netbeans 7.2的上下文菜单中包含一个“测试单个文件”目标

包含的链接概述了创建一个名为“test.single”的操作(为了覆盖 Netbeans 的测试单个文件命令),并且在该操作创建中,必须指定一个 ant 目标和一个上下文对象,如下所示:

<context>
    <property>testclass</property>
    <folder>${current.dir}</folder>
    <pattern>\.java$</pattern>
    <format>java-name</format>
    <arity>
        <one-file-only/>
    </arity>
 </context>

总而言之,我有:

在 ide-actions 块中的 project.xml 中创建操作:

<action name="test.single">                                     
  <target>test-single</target>

  <context>
      <property>testclass</property>
      <folder>${current.dir}</folder>
      <pattern>\.java$</pattern>
      <format>java-name</format>
      <arity>
          <one-file-only/>
      </arity>
  </context>
</action>

将 ide-action 添加到上下文菜单块”

<ide-action name="test.single"/>

Adding this to the free-form project's project.xml file yields a grayed out "test.single" entry in the context menu upon right-clicking on the project name. Further, right clicking on a test class in my src/test directory yields a grayed out "Test Single File" entry.

I've checked and validated the xml and it all seems to check out. What could I be doing wrong?

thanks in advance!

4

1 回答 1

1

Had the same problem and managed to solve it by cloning the action run.single in by nbproject/project.xml and calling it test.single:

<action name="test.single">
    <script>build.xml</script>
    <target>test-single</target>
    <context>
        <property>test.class</property>
        <folder>src/java</folder>
        <pattern>\.java$</pattern>
        <format>java-name</format>
        <arity>
            <one-file-only/>
        </arity>
    </context>
</action>

I also changed the property to test.class as we need this in the projects build.xml to run the appropriate test class.

In the main build.xml I have a target test-single:

<target name="test-single" description="Run individual Unit tests" depends="compile, compile-test" >  
    <junit
        printsummary="yes"
        errorProperty="test.failed"
        failureproperty="test.failed"
        haltonfailure="yes" 
        fork="yes"
        showoutput="yes">
        <formatter type="plain" usefile="false"/>
        <classpath>
            <pathelement location="${build.base.classes.dir}" />
            <pathelement location="${unit.test.classes.dir}" />
            <pathelement location="${junit.dir}" />
        </classpath>
        <test name="${test.class}Test" todir="${results}">
        </test>
    </junit>
    <fail message="Tests failed!" if="test.failed"/>
</target>

Note that the refers to the property ${test.class}. But when I leave it like that it tries to run the class being tested instead of the JUnit test class. Since this is always called the same as the class being tested with the word "Test" at the end I have written it so that the name is ${test.class}Test.

于 2013-07-11T19:53:16.073 回答