Note that there are some explanatory texts on larger screens.

plurals
  1. POGuide for Testing Gradle Scripts
    primarykey
    data
    text
    <p>What are the best practices for testing <a href="http://www.gradle.org/">Gradle</a> Scripts?</p> <p>I currently unit test my <a href="http://ant.apache.org/">ant</a> scripts with <a href="http://ant.apache.org/antlibs/antunit/">antunit</a>, but I'm looking to migrate to Gradle. I can only find articles on testing Java code from Gradle or Groovy, but nothing on testing the Gradle tasks that I create or testing Groovy in general. Is there an equivalent of antunit for Gradle? Has anyone played with a BDD framework (like <a href="http://cukes.info/">cucumber</a>) to test Gradle scripts?</p> <p>For instance, I currently have the following Ant Target</p> <pre><code>&lt;target name="dist-bin" depends="build" description="creates a zip distribution of the current build"&gt; &lt;zip destfile="build/TIBant-bin.zip"&gt; &lt;zipfileset dir="src/ant" includes="**" /&gt; &lt;zipfileset dir="test" includes="**" prefix="test" /&gt; &lt;zipfileset dir="build" includes="TIBant.jar" /&gt; &lt;zipfileset dir="build" includes="TIBant-*.html" /&gt; &lt;zipfileset dir="build/examples/XMLtoProperties" includes="XMLtoProperties.html" prefix="examples/XMLtoProperties" /&gt; &lt;zipfileset dir="lib" includes="**" prefix="lib" /&gt; &lt;zipfileset dir="src/xslt" includes="**" excludes="test/**,userguide.xslt" prefix="lib/xslt" /&gt; &lt;zipfileset dir="." includes="copyright.html,LICENSE.txt" /&gt; &lt;zipfileset dir="examples" includes="**" excludes="**/build/**,**/config/default.properties" prefix="examples" /&gt; &lt;/zip&gt; &lt;/target&gt; </code></pre> <p>As you can imagine, it's pretty easy to break this when refactoring the project, so I have the following antunit test to check it.</p> <pre><code>&lt;target name="test-dist-bin"&gt; &lt;delete file="build/TIBant-bin.zip" /&gt; &lt;au:assertFalse message="Bin dist still present"&gt; &lt;available file="build/TIBant-bin.zip" /&gt; &lt;/au:assertFalse&gt; &lt;antcall target="dist-bin" /&gt; &lt;au:assertTrue message="Bin dist not created"&gt; &lt;available file="build/TIBant-bin.zip" /&gt; &lt;/au:assertTrue&gt; &lt;delete dir="build/testBinDist" /&gt; &lt;au:assertFalse message="TestBinDist still present"&gt; &lt;available file="build/testBinDist" /&gt; &lt;/au:assertFalse&gt; &lt;mkdir dir="build/testBinDist" /&gt; &lt;unzip src="build/TIBant-bin.zip" dest="build/testBinDist" /&gt; &lt;au:assertFalse message="config dir present"&gt; &lt;available file="build/testBinDist/config/default.properties" /&gt; &lt;/au:assertFalse&gt; &lt;au:assertTrue message="Ant Macros missing"&gt; &lt;available file="build/testBinDist/tibant.xml" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertTrue message="Engine Stopper Jar missing"&gt; &lt;available file="build/testBinDist/TIBant.jar" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertTrue message="Ant-contrib-missing"&gt; &lt;available file="build/testBinDist/lib/ant-contrib-1.0b3.jar" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertTrue message="ant-unit missing"&gt; &lt;available file="build/testBinDist/lib/ant-antunit-1.2.jar" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertTrue message="Copyright missing"&gt; &lt;available file="build/testBinDist/copyright.html" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertTrue message="License missing"&gt; &lt;available file="build/testBinDist/LICENSE.txt" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertFalse message="Src present"&gt; &lt;available file="build/testBinDist/src/java/org/windyroad/tibant/EngineStopper.jar" /&gt; &lt;/au:assertFalse&gt; &lt;au:assertTrue message="example missing"&gt; &lt;available file="build/testBinDist/examples/SimpleProject/src/bw/example/Build/example.archive" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertFalse message="example has build files"&gt; &lt;available file="build/testBinDist/examples/SimpleProject/build/*" /&gt; &lt;/au:assertFalse&gt; &lt;au:assertFalse message="example has default config file"&gt; &lt;available file="build/testBinDist/examples/SimpleProject/config/default.properties" /&gt; &lt;/au:assertFalse&gt; &lt;property name="doc.file" location="build/testBinDist/TIBant-User-Guide.html" /&gt; &lt;au:assertTrue message="doc missing: ${doc.file}"&gt; &lt;available file="${doc.file}" /&gt; &lt;/au:assertTrue&gt; &lt;au:assertTrue message="xslt missing"&gt; &lt;available file="build/testBinDist/lib/xslt/configure-ear.xslt" /&gt; &lt;/au:assertTrue&gt; &lt;subant target="run-quick-tests"&gt; &lt;fileset dir="build/testBinDist" includes="build.xml" /&gt; &lt;/subant&gt; &lt;/target&gt; </code></pre> <p>which is called by the following snippet to produce a nice xml report</p> <pre><code> &lt;au:antunit failonerror="@{failonerror}"&gt; &lt;propertyset&gt; &lt;propertyref name="config.filename" /&gt; &lt;/propertyset&gt; &lt;path&gt; &lt;pathelement location="@{antunit}" /&gt; &lt;/path&gt; &lt;au:plainlistener logLevel="info" /&gt; &lt;au:xmllistener todir="build" loglevel="info" /&gt; &lt;/au:antunit&gt; </code></pre> <p>I understand how to migrate <code>dist-bin</code> to gradle, but I'm not sure what's the right way to migrate <code>test-dist-bin</code> and the <code>au:antunit</code> call.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload