Ho un progetto netbeans, e ho anche groovy per i test di spock. Quando right-click sul progetto e dico di prova, viene eseguito un compito chiamatoPerché l'esecuzione di test-with-groovy dalla riga di comando ant in un progetto netbeans esegue i test?
test-with-groovy
ma quando ho eseguito ant test-con-groove i test vengono compilati ma non eseguito. Mi sento come se qualcosa dovesse essere aggiunto dall'ide di netbeans, ma non ho idea di cosa e mezza giornata di ricerche non ha prodotto risultati.
Qualcuno può aiutarmi?
Ecco come è possibile ottenere i risultati che sto ottenendo:
ho creato un semplice progetto Java con un semplice principale in NetBeans 8.0.2
package simpleantjava;
public class SimpleAntJava {
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Main Ran");
}
}
poi ho creato due file di test, uno un file 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.");
}
}
e uno un groove prova di Spock base:
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
}
}
se corro il test di NetBeans, l'uscita dice che è in esecuzione:
ant -f /home/vextorspace/NetBeansProjects/SimpleAntJava -Dtest.binarytestincludes=**/*Test.class -Dtest.binaryincludes= -Dtest.binaryexcludes=**/*$* test-with-groovy
ma se corro che nella riga di comando formica non viene eseguito alcun test (anche se dà nessun errore o) Compila entrambi i file di test in file di classe in build/test/classi.
Se eseguo ant clean test, crea entrambi i file di test ma non esegue il test groovy, solo il test java.
l'accumulo impl.xml ha le definizioni per la prova (non voglio includere l'intero file, ma è quella standard creato da NetBeans: ecco le sezioni in cui credo:
<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>
e il target ant test-con-Groovy è incluso nel groove-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>
Devo confessare che non so cosa stiano realmente facendo i macrodef. Ma ho provato a cambiare **/* Test.java in **/* Test.groovy, **/* Test.class e **/Test. inutilmente.
Qualcuno sa come farlo funzionare? Non voglio buttare giù l'intero processo di compilazione perché sto lavorando a un progetto legacy di 6 anni con il plug-in di jogl e un sacco di elementi personalizzati nel file ant, quindi vorrei capire come per far funzionare questo
Grazie!
Avete tr eseguire 'ant' in modalità debug per vedere cosa sta succedendo? Il comando è - 'ant -debug' – Rao
Hai fatto la stessa cosa che hai descritto. L'unica cosa è che sto avendo solo il "test di passaggio" in "groovy junit class". Questo funziona correttamente usando l'IDE di Netbeans. E quando si esegue lo stesso comando su 'commoand-prompt', ottenendo l'errore come mostrato in [schermata] (http://s000.tinyupload.com/index.php?file_id=18629142873163433142). Quindi stai affrontando lo stesso? – Rao
Sembra che 'NewGroovyTest' sia completamente _independent_ test usando' Spock' e nessuna relazione con altre classi. – Rao