Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Implement the force-apex-test-run task
Browse files Browse the repository at this point in the history
  • Loading branch information
mcartoixa committed Jul 25, 2018
1 parent f48bef7 commit 7af5cec
Show file tree
Hide file tree
Showing 12 changed files with 643 additions and 9 deletions.
201 changes: 201 additions & 0 deletions docs/force-apex-test-run.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Copyright 2018 Mathieu Cartoixa.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-us">
<head>
<title>force-apex-test-run Task</title>
<link rel="stylesheet" type="text/css" href="css/index.css" />
</head>

<body>
<h2>force-apex-test-run Task</h2>

<h3>Description</h3>
<p>Runs Apex tests.</p>
<p>It executes the <a href="https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_apex.htm#cli_reference_test_run" target="_blank">force-apex-test-run</a> command.</p>
<p><strong>Note</strong>: This task depends on the same external libraries as the <a href="https://ant.apache.org/manual/Tasks/junitreport.html">junitreport</a> task.
See <a href="https://ant.apache.org/manual/install.html#librarydependencies">Library Dependencies</a> for more
information.</p>

<h3>Parameters</h3>
<p>In addition to <a href="common.html">the attributes used by every ant-sfdx task</a>, this task uses the following attributes:</p>
<table class="attr">
<thead>
<tr>
<th scope="col">Attribute</th>
<th scope="col">Command line equivalent</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
</thead>
<tbody>
<tr>
<td>synchronous</td>
<td>-y</td>
<td>Indicates whether test methods from a single Apex class are run synchronously.</td>
<td>No; defaults to <q>false</q>.</td>
</tr>
<tr>
<td>targetusername</td>
<td>-u</td>
<td>A username or alias for the target org.</td>
<td>No</td>
</tr>
<tr>
<td>testlevel</td>
<td>-l</td>
<td>Specifies which tests to run. Accepatble values are:
<ul>
<li><q>RunAllTestsInOrg</q>: all tests in your org and in installed managed packages are run.</li>
<li><q>RunLocalTests</q>: all tests in your org are run, except the ones that originate from installed managed packages.</li>
<li><q>RunSpecifiedTests</q>: only the tests that you specify are run.</li>
</ul>
</td>
<td>No</td>
</tr>
<tr>
<td>todir</td>
<td>-d</td>
<td>The directory to store test run files.</td>
<td>No</td>
</tr>
<tr>
<td>tofile</td>
<td />
<td>The file to copy the JUnit results to.</td>
<td>No</td>
</tr>
<tr>
<td>wait</td>
<td>-w</td>
<td>The streaming client socket timeout, in minutes.</td>
<td>No; defaults to <q>6</q>.</td>
</tr>
</tbody>
</table>

<h3>Parameters specified as nested elements</h3>

<h4>class</h4>
<p>Specifies an Apex test class name to run. This parameter cannot be used in conjonction with a <var>suite</var> or a <var>test</var> parameter.</p>

<h4>suite</h4>
<p>Specifies an Apex test suite to run. This parameter cannot be used in conjonction with a <var>class</var> or a <var>test</var> parameter.</p>

<h4>test</h4>
<p>Specifies an Apex test class name or ID and test method, if applicable, to run. This parameter cannot be used in conjonction with a <var>class</var> or a <var>suite</var> parameter.</p>

<h4>report</h4>
<p>Generate a browsable report.</p>
<h5>Parameters</h5>
<table class="attr">
<tr>
<th scope="col">Attribute</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
<tr>
<td>format</td>
<td>The format of the generated report. Must be either <q>noframes</q> or <q>frames</q>.</td>
<td>No; defaults to <q>frames</q></td>
</tr>
<tr>
<td>styledir</td>
<td>The directory where the stylesheets are defined. They must be conforming to the following
conventions:
<ul>
<li><q>frames</q> format: the stylesheet must be named <samp>junit-frames.xsl</samp>,
or <samp>junit-frames-saxon.xsl</samp> if you are using Saxon 9+.</li>
<li><q>noframes</q> format: the stylesheet must be named <samp>junit-noframes.xsl</samp>,
or <samp>junit-noframes-saxon.xsl</samp> if you are using Saxon 9+.</li>
</ul>
</td>
<td>No; defaults to embedded stylesheets</td>
</tr>
<tr>
<td>todir</td>
<td>The directory where the files resulting from the transformation should be written to.</td>
<td>No; defaults to current directory</td>
</tr>
</table>
<p>This task assumes the following concerning the <q>frames</q> and <q>noframes</q> formats:</p>
<ul>
<li>The <q>frames</q> format uses a stylesheet which is generating output <em>only</em> by
redirecting.</li>
<li>The <q>noframes</q> format does not use redirecting and generates one file
called <samp>junit-noframes.html</samp>.</li>
</ul>
<p>Custom versions of <samp>junit-frames.xsl</samp> or <samp>junit-noframes.xsl</samp> must adhere
to the above conventions.</p>
<h5>Nested element of the report tag</h5>
<h6>param</h6>
<p><em>Since Ant 1.7</em>, the <var>report</var> tag supports nested <code>param</code> tags. These
tags can pass XSL parameters to the stylesheet.</p>
<table class="attr">
<tr>
<th scope="col">Attribute</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
<tr>
<td>name</td>
<td>Name of the XSL parameter</td>
<td>Yes</td>
</tr>
<tr>
<td>expression</td>
<td>Text value to be placed into the <code>param</code>.<br/>Was originally intended to be an
XSL expression.</td>
<td>Yes</td>
</tr>
<tr>
<td>if</td>
<td>The <code>param</code> will only be passed <a href="https://ant.apache.org/manual/properties.html#if+unless">if this
property is set</a>.</td>
<td>No</td>
</tr>
<tr>
<td>unless</td>
<td>The <code>param</code> will not be passed <a href="https://ant.apache.org/manual/properties.html#if+unless">if this
property is set</a>.</td>
<td>No</td>
</tr>
</table>

<p>The built-in stylesheets support the following parameters:</p>
<table>
<tr>
<th scope="col">XSL Parameter</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
<tr>
<td>TITLE</td>
<td>Title used in <code>&lt;title&gt;</code> and <code>&lt;h1&gt;</code> tags</td>
<td>No; defaults to <q>Unit Test Results</q></td>
</tr>
</table>

<h6>classpath</h6>
<p><em>Since Ant 1.9.5</em>. Like for the <a href="https://ant.apache.org/manual/Tasks/style.html#classpath">XSLT task</a>, a
nested <code>&lt;classpath&gt;</code> will be used to load the processor.</p>

<h6>factory</h6>
<p><em>Since Ant 1.9.5</em>. Like for the <a href="https://ant.apache.org/manual/Tasks/style.html#classpath">XSLT task</a>, a
nested <code>&lt;factory&gt;</code> can be used to specify factory settings.</p>
</body>
</html>
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h2>Usage</h2>
<h2>Tasks</h2>
<ul>
<li><a href="force-apex-execute.html">force-apex-execute</a></li>
<li><a href="force-apex-test-run.html">force-apex-test-run</a></li>
<li><a href="force-data-record-create.html">force-data-record-create</a></li>
<li><a href="force-data-tree-import.html">force-data-tree-import</a></li>
<li><a href="force-limits-api-display.html">force-limits-api-display</a></li>
Expand Down
2 changes: 1 addition & 1 deletion ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependencies>
<dependency org="org.json" name="json" rev="20180130" conf="compile->default" />
<dependency org="junit" name="junit" rev="4.12" conf="test->default" />
<dependency org="xalan" name="xalan" rev="2.7.2" conf="test->default" />
<dependency org="xalan" name="xalan" rev="2.7.2" conf="compile,test->default" />
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.5.6" conf="build->default" />
</dependencies>
</ivy-module>
7 changes: 4 additions & 3 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Thu, 19 Jul 2018 17:04:20 +0200
#Tue, 24 Jul 2018 17:24:28 +0200
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
Expand Down Expand Up @@ -31,10 +31,11 @@ endorsed.classpath=
excludes=tmp/
file.reference.ant-sfdx-src=src/main
file.reference.ant.jar=.tmp/apache-ant-1.9.12/lib/ant.jar
file.reference.ant-junit.jar=.tmp/apache-ant-1.9.12/lib/ant-junit.jar
file.reference.ant-testutil.jar=.tmp/apache-ant-1.9.12/lib/ant-testutil.jar
includes=**
jar.compress=true
javac.classpath=${file.reference.ant.jar}\:${ivy.compile.classpath}
javac.classpath=${file.reference.ant.jar}\:${file.reference.ant-junit.jar}\:${ivy.compile.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down Expand Up @@ -70,7 +71,7 @@ run.test.classpath=${javac.test.classpath}\:${build.test.classes.dir}
source.encoding=UTF-8
src.dir=${file.reference.ant-sfdx-src}

ivy.compile.classpath=ivy/lib/compile/json.jar
ivy.compile.classpath=ivy/lib/compile/json.jar\:ivy/lib/compile/serializer.jar\:ivy/lib/compile/xalan.jar\:ivy/lib/compile/xml-apis.jar
test.test.dir=src/test

ivy.test.classpath=ivy/lib/test/hamcrest-core.jar\:ivy/lib/test/junit.jar\:ivy/lib/test/serializer.jar\:ivy/lib/test/xalan.jar\:ivy/lib/test/xml-apis.jar
4 changes: 2 additions & 2 deletions src/main/com/mcartoixa/ant/sfdx/JsonOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ protected void processLine(final String string) throws IOException {
final JSONObject json = new JSONObject(string);
parser.parse(json);
} catch (JSONException jex) {
parser.log(jex.getLocalizedMessage(), Project.MSG_WARN);
parser.log(string, Project.MSG_DEBUG);
parser.log(jex.getLocalizedMessage(), Project.MSG_DEBUG);
parser.log(string, Project.MSG_WARN);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/com/mcartoixa/ant/sfdx/SfdxTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public void execute() throws BuildException {
exe.setCommandline(cmd.getCommandline());
final int r = exe.execute();

this.onExecuted(r);

if (this.getFailOnError() && Execute.isFailure(r) || this.hasErrorMessage()) {
String message = this.errorMessage;
if (message == null || message.isEmpty()) {
Expand Down Expand Up @@ -215,6 +217,10 @@ protected boolean hasErrorMessage() {
return this.errorMessage != null && !this.errorMessage.isEmpty();
}

@SuppressWarnings("PMD.EmptyMethodInAbstractClassShouldBeAbstract")
protected void onExecuted(final int result) {
}

protected void setErrorMessage(final String message) {
this.errorMessage = message;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/com/mcartoixa/ant/sfdx/antlib.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<antlib>
<taskdef name="force-apex-execute" classname="com.mcartoixa.ant.sfdx.force.apex.ExecuteTask" />
<taskdef name="force-apex-test-run" classname="com.mcartoixa.ant.sfdx.force.apex.test.RunTask" />
<taskdef name="force-data-record-create" classname="com.mcartoixa.ant.sfdx.force.data.record.CreateTask" />
<taskdef name="force-data-tree-import" classname="com.mcartoixa.ant.sfdx.force.data.tree.ImportTask" />
<taskdef name="force-limits-api-display" classname="com.mcartoixa.ant.sfdx.force.lmiits.api.DisplayTask" />
<taskdef name="force-limits-api-display" classname="com.mcartoixa.ant.sfdx.force.limits.api.DisplayTask" />
<taskdef name="force-org-create" classname="com.mcartoixa.ant.sfdx.force.org.CreateTask" />
<taskdef name="force-org-delete" classname="com.mcartoixa.ant.sfdx.force.org.DeleteTask" />
<taskdef name="force-org-display" classname="com.mcartoixa.ant.sfdx.force.org.DisplayTask" />
Expand Down
Loading

0 comments on commit 7af5cec

Please sign in to comment.