2016-01-09 9 views
6

私はnetbeansプロジェクトを持っていますが、私はspockテストのためにもそれが面白いです。私は、プロジェクトを右クリックして、テストを言うとき、それはnetbeansプロジェクトのantコマンドラインからtest-with-groovyを実行してテストを実行しないのはなぜですか?

test-with-groovy 

と呼ばれるタスクを実行しますが、私はアリテストで、グルーヴィーを実行するとテストがコンパイルされますが実行されません。私はnetbeans ideによって追加されなければならない何かのように感じますが、私は検索の半日が何も結果を網羅していないと考えていません。

誰でも手伝ってもらえますか?ここで

あなたは私が取得しています結果を得ることができる方法である。

私は8.0.2

package simpleantjava; 

public class SimpleAntJava { 

    public static void main(String[] args) { 
     // TODO code application logic here 
     System.out.println("Main Ran"); 
    } 

} 

NetBeansでシンプルなメイン持つ単純なJavaプロジェクトを作成した後、私は2つのテストファイル、1を作成しましたJUnitのJavaファイル:

package simpleantjava; 

import org.junit.After; 
import org.junit.AfterClass; 
import org.junit.Before; 
import org.junit.BeforeClass; 
import org.junit.Test; 
import static org.junit.Assert.*; 

/** 
* 
* @author vextorspace 
*/ 
public class SimpleAntJavaTest { 

    public SimpleAntJavaTest() { 
    } 

    @BeforeClass 
    public static void setUpClass() { 
    } 

    @AfterClass 
    public static void tearDownClass() { 
    } 

    @Before 
    public void setUp() { 
    } 

    @After 
    public void tearDown() { 
    } 

    /** 
    * Test of main method, of class SimpleAntJava. 
    */ 
    @Test 
    public void testMain() { 
     System.out.println("main"); 
     String[] args = null; 
     SimpleAntJava.main(args); 
     // TODO review the generated test code and remove the default call to fail. 
     fail("Main JUnit Test is a prototype."); 
    } 

} 

と1グルーヴィーなベーススポック試験:

package simpleantjava 

import org.junit.Test 
import spock.lang.Specification 

/** 
* 
* @author vextorspace 
*/ 
class NewGroovyTest extends Specification{ 
    @Test 
    def "Our groovy test should run"() { 
     expect: 
      true 
    } 

    @Test 
    def "Failing tests should fail"() { 
     expect: 
      false 
    } 
} 

私は、NetBeansからテストを実行する場合、出力は、それが実行されていると言う:

ant -f /home/vextorspace/NetBeansProjects/SimpleAntJava -Dtest.binarytestincludes=**/*Test.class -Dtest.binaryincludes= -Dtest.binaryexcludes=**/*$* test-with-groovy 

が、私は(それがいずれかのエラーを与えていないが)antコマンドラインで、それがどのテストを実行しないことを実行した場合両方のテストファイルをbuild/test/classesのクラスファイルにコンパイルします。

antクリーンテストを実行すると、両方のテストファイルがビルドされますが、Groovyテストは実行されず、Javaテストのみが実行されます。

ビルドimpl.xmlは、テストの定義(私はファイル全体は含まれませんが、それは、NetBeansで作成された標準的なものであるがあります。ここで私は信じて関連するセクションは以下のとおりです。

<target if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}"> 
    <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> 
     <attribute default="${includes}" name="includes"/> 
     <attribute default="${excludes}" name="excludes"/> 
     <attribute default="**" name="testincludes"/> 
     <attribute default="" name="testmethods"/> 
     <element name="customize" optional="true"/> 
     <sequential> 
      <property name="junit.forkmode" value="perTest"/> 
      <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> 
       <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/> 
       <syspropertyset> 
        <propertyref prefix="test-sys-prop."/> 
        <mapper from="test-sys-prop.*" to="*" type="glob"/> 
       </syspropertyset> 
       <formatter type="brief" usefile="false"/> 
       <formatter type="xml"/> 
       <jvmarg value="-ea"/> 
       <customize/> 
      </junit> 
     </sequential> 
    </macrodef> 
</target> 
<target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}"> 
    <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> 
     <attribute default="${includes}" name="includes"/> 
     <attribute default="${excludes}" name="excludes"/> 
     <attribute default="**" name="testincludes"/> 
     <attribute default="" name="testmethods"/> 
     <element name="customize" optional="true"/> 
     <sequential> 
      <property name="junit.forkmode" value="perTest"/> 
      <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> 
       <batchtest todir="${build.test.results.dir}"> 
        <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> 
         <filename name="@{testincludes}"/> 
        </fileset> 
        <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}"> 
         <filename name="${test.binarytestincludes}"/> 
        </fileset> 
       </batchtest> 
       <syspropertyset> 
        <propertyref prefix="test-sys-prop."/> 
        <mapper from="test-sys-prop.*" to="*" type="glob"/> 
       </syspropertyset> 
       <formatter type="brief" usefile="false"/> 
       <formatter type="xml"/> 
       <jvmarg value="-ea"/> 
       <customize/> 
      </junit> 
     </sequential> 
    </macrodef> 
</target> 
<target depends="-init-macrodef-junit-init,-init-macrodef-junit-single, -init-macrodef-junit-batch" if="${junit.available}" name="-init-macrodef-junit"/> 

...

<!--                                                    
      =======================                                            
      TEST EXECUTION SECTION                                            
      =======================                                            
     --> 
<target depends="init" if="have.tests" name="-pre-test-run"> 
<mkdir dir="${build.test.results.dir}"/> 
</target> 
<target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run"> 
<j2seproject3:test includes="${includes}" testincludes="**/*Test.java"/> 
</target> 
<target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run"> 
    <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> 
</target> 
<target depends="init" if="have.tests" name="test-report"/> 
<target depends="init" if="netbeans.home+have.tests" name="-test-browse"/> 
<target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/> 
<target depends="init" if="have.tests" name="-pre-test-run-single"> 
<mkdir dir="${build.test.results.dir}"/> 
</target> 

とテストと、グルーヴィーなAntターゲットに含まグルーヴィー-のbuild.xmlである:

<target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run-with-groovy"> 
    <j2seproject3:test testincludes=""/> 
</target> 
<target depends="init,compile-test,-pre-test-run,-do-test-run-with-groovy" if="have.tests" name="-post-test-run-with-groovy"> 
    <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> 
</target> 
<target depends="init,compile-test,-pre-test-run,-do-test-run-with-groovy,test-report,-post-test-run-with-groovy,-test-browse" description="Run unit tests." name="test-with-groovy"/> 
<target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single-groovy"> 
    <fail unless="test.binarytestincludes">Must select some files in the IDE or set test.includes</fail> 
    <j2seproject3:test testincludes=""/> 
</target> 

私は、マクロ定義が実際に何をしているのかわからないと告白する必要があります。しかし、**/* Test.javaを**/* Test.groovy、**/* Test.class、**/Testに変更しようとしました。をご利用いただけません。

誰でもこの作業を行う方法を知っていますか?私は実際には6年のジョグルプラグインとantファイルの多くのカスタムものでレガシープロジェクトに取り組んでいるので、ビルドプロセス全体を捨てる必要はありませんので、この仕事をする

ありがとうございました!

+0

tr何が起きているのかを見るためにデバッグモードで 'ant'を実行していますか?コマンドは - 'ant -debug' – Rao

+0

あなたと同じことを説明しました。唯一のことは、「グルーヴィージュニットクラス」で「合格テスト」しかないことです。これは 'Netbeans IDE'を使ってOKです。 'commoand-prompt'で同じコマンドを実行すると、[screen shot](http://s000.tinyupload.com/index.php?file_id=18629142873163433142)のようにエラーになります。あなたは同じように直面していますか? – Rao

+0

'NewGroovyTest'は' Spock'を使って完全に_独立したテストで、他のクラスとの関係はないようです。 – Rao

答えて

1

NewGroovyTestは、Spockを使用して完全に独立したテストであり、他のクラスとの関係はありません。

test/**/* Testで定義されたクラスを含めるには。groovy files私はコンパイルされたクラスを(すべてのGroovyがJavaにコンパイルするように)とり、JUnitにそれらを渡しています。前述のように、デフォルトの動作では、* Test.javaファイルに由来するクラスのみが使用されます。

このリンクはあなたを助ける:Groovy Unit Tests

具体的には、以下を追加:

<target name="-post-test-run-with-groovy"> 
<junit dir="${work.dir}" errorproperty="tests.failed" 
     failureproperty="tests.failed" fork="true" 
     showoutput="true"> 
    <batchtest todir="${build.test.results.dir}"> 
    <fileset dir="${build.test.classes.dir}"> 
     <include name="**/*Test.class"/> 
     <exclude name="**/*$*"/> 
    </fileset> 
    </batchtest> 
    <classpath> 
    <path path="${run.test.classpath}"/> 
    </classpath> 
    <syspropertyset> 
    <propertyref prefix="test-sys-prop."/> 
    <mapper from="test-sys-prop.*" to="*" type="glob"/> 
    </syspropertyset> 
    <formatter type="brief" usefile="false"/> 
    <formatter type="xml"/> 
    <jvmarg line="${run.jvmargs}"/> 
</junit> 

<mkdir dir="${build.test.results.dir}/../report"/> 
<mkdir dir="${build.test.results.dir}/../report/html"/> 

<junitreport todir="${build.test.results.dir}/../report"> 
    <fileset dir="${build.test.results.dir}"> 
    <include name="TEST-*.xml"/> 
    </fileset> 
    <report format="frames" todir="${build.test.results.dir}/../report/html"/> 
</junitreport> 

をbuild.xmlファイルにテストはコマンドで実行することができます

ant -f ~/NetBeansProjects/jdesigner -Dtest.binarytestincludes=**/*Test.class -Dtest.binaryincludes= -Dtest.binaryexcludes=**/* test-with-groovy 
+0

興味深いことに、nbproject/build-impl.xmlを修正するには、**/* Test.groovyを-do-test-runターゲットのtestincludesに追加してみました。私はこれを前に試したが、何かを台無しにしているに違いない。これには、Javaテストを2回実行しないという利点がありますが、欠点はbuild-impl.xmlが自動生成されることです。そのテンプレートがどこから来たのか誰にも知られていますか? – vextorspace

関連する問題