Author: buildbot
Date: Wed May 4 12:40:13 2016
New Revision: 987456
Log:
Staging update by buildbot for sling
Modified:
websites/staging/sling/trunk/content/ (props changed)
websites/staging/sling/trunk/content/documentation/tutorials-how-tos/testing-sling-based-applications.html
Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed May 4 12:40:13 2016
@@ -1 +1 @@
-1741598
+1742262
Modified:
websites/staging/sling/trunk/content/documentation/tutorials-how-tos/testing-sling-based-applications.html
==============================================================================
---
websites/staging/sling/trunk/content/documentation/tutorials-how-tos/testing-sling-based-applications.html
(original)
+++
websites/staging/sling/trunk/content/documentation/tutorials-how-tos/testing-sling-based-applications.html
Wed May 4 12:40:13 2016
@@ -126,7 +126,14 @@ h2:hover > .headerlink, h3:hover > .head
</li>
<li><a href="#pax-exam">Pax Exam</a></li>
<li><a href="#server-side-junit-tests">Server-side JUnit tests</a></li>
-<li><a href="#http-based-integration-tests">HTTP-based integration
tests</a></li>
+<li><a href="#http-based-integration-tests">HTTP-based integration
tests</a><ul>
+<li><a href="#starting-an-integration-test"><a name="starting"></a> Starting
an Integration Test</a><ul>
+<li><a href="#maven-dependency">Maven Dependency</a></li>
+<li><a href="#simple-example-using-slinginstancerule">Simple Example using
SlingInstanceRule</a></li>
+</ul>
+</li>
+</ul>
+</li>
<li><a href="#summary">Summary</a></li>
</ul>
</div>
@@ -171,15 +178,71 @@ such as the <a href="http://junit-addons
<p>The tools described on the <a
href="/documentation/bundles/org-apache-sling-junit-bundles.html">JUnit
server-side testing support</a> page allow for
running JUnit tests on an live Sling instance, as part of the normal
integration testing cycle. </p>
<h2 id="http-based-integration-tests">HTTP-based integration tests<a
class="headerlink" href="#http-based-integration-tests" title="Permanent
link">¶</a></h2>
-<p>The highest level of integration is testing a complete Sling instance via
its HTTP interface.</p>
-<p>We use this technique to test Sling itself: the <a
href="https://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests">launchpad/integration-tests</a>
module defines the tests (462 of them as I write this), and the <a
href="https://svn.apache.org/repos/asf/sling/trunk/launchpad/testing">launchpad/testing</a>
module executes them, after setting up a Sling instance from scratch (which is
quite easy as Sling is just a runnable jar). </p>
-<p>A simple mechanism (described in README files in these modules) allows
individual tests to be executed quickly against a previously started Sling
instance, to be able to write and debug tests efficiently.</p>
-<p>The test code could be made simpler using the fluent HTTP interfaces
defined in the Sling testing tools described above, but the launchpad tests
were written before that module was created, and as they're stable there's no
reason to rewrite them. If you're planning on using this technique for your own
applications, we recommend looking at the Sling testing tools instead of these
"legacy" tests - but the basic technique is the same.</p>
-<p>One problem with these launchpad tests is that the tests of all Sling
modules are defined in a single testing module, they are not co-located with
the code that they test. This could be improved by providing the tests in
bundles that can be created from the same Maven modules that the code that they
test.</p>
+<p>The <a
href="https://svn.apache.org/repos/asf/sling/trunk/testing/junit/rules">Sling
HTTP Testing Rules</a> allow writing integration tests easily. They are
primarily meant to be used for tests that use http against
+a Sling instance and make use of the <a
href="https://svn.apache.org/repos/asf/sling/trunk/testing/http/clients">org.apache.sling.testing.clients</a>
which offer a simple, immutable and extendable way of working
+with specialized testing clients.</p>
+<p>The JUnit rules incorporate boiler-plate logic that is shared in tests and
take the modern approach of using rules rather than
+inheritance. The <code>SlingRule</code> (for methods) or
<code>SlingClassRule</code> (for test classes) are base rules, chaining other
rules like <code>TestTimeoutRule</code>,
+<code>TestDescriptionRule</code>, <code>FilterRule</code>. The
<code>SlingInstanceRule</code> extends that and starts a Sling instance if
needed and also allows
+instantiating a <code>SlingClient</code> pointing to the instance and
automatically configure the base url, credentials, etc.</p>
+<h3 id="starting-an-integration-test"><a name="starting"></a> Starting an
Integration Test<a class="headerlink" href="#starting-an-integration-test"
title="Permanent link">¶</a></h3>
+<p>Starting an integration is very simple out of the box, but is very
extendable, both by combining or configuring the junit rules and by
+using the versatile <code>SlingClient</code> (which can be extended or adapted
by calling <code>adaptTo(MyClient.class)</code> without losing the client
+configuration)</p>
+<p>The <a
href="https://svn.apache.org/repos/asf/sling/trunk/testing/junit/rules/README.md">README</a>
provides more detail, as do <a
href="https://svn.apache.org/repos/asf/sling/trunk/testing/junit/rules/src/test/java">the
tests</a>.
+The <a
href="https://svn.apache.org/repos/asf/sling/trunk/testing/http/clients">Sling
HTTP Testing Clients</a> provide simple explanations, and unit tests.</p>
+<h4 id="maven-dependency">Maven Dependency<a class="headerlink"
href="#maven-dependency" title="Permanent link">¶</a></h4>
+<table class="codehilitetable"><tr><td class="linenos"><div
class="linenodiv"><pre>1
+2
+3
+4
+5</pre></div></td><td class="code"><div class="codehilite"><pre><span
class="nt"><dependency></span>
+ <span class="nt"><groupId></span>org.apache.sling<span
class="nt"></groupId></span>
+ <span
class="nt"><artifactId></span>org.apache.sling.testing.rules<span
class="nt"></artifactId></span>
+ <span class="nt"><version></span>0.1.0-SNAPSHOT<span
class="nt"></version></span>
+<span class="nt"></dependency></span>
+</pre></div>
+</td></tr></table>
+
+<h4 id="simple-example-using-slinginstancerule">Simple Example using
SlingInstanceRule<a class="headerlink"
href="#simple-example-using-slinginstancerule" title="Permanent
link">¶</a></h4>
+<table class="codehilitetable"><tr><td class="linenos"><div
class="linenodiv"><pre> 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16</pre></div></td><td class="code"><div class="codehilite"><pre><span
class="kd">public</span> <span class="kd">class</span> <span
class="nc">MySimpleIT</span> <span class="o">{</span>
+
+ <span class="nd">@ClassRule</span>
+ <span class="kd">public</span> <span class="kd">static</span> <span
class="n">SlingInstanceRule</span> <span class="n">instanceRule</span> <span
class="o">=</span> <span class="k">new</span> <span
class="n">SlingInstanceRule</span><span class="o">();</span>
+
+ <span class="nd">@Rule</span>
+ <span class="kd">public</span> <span class="n">SlingRule</span> <span
class="n">methodRule</span> <span class="o">=</span> <span class="k">new</span>
<span class="n">SlingRule</span><span class="o">();</span> <span class="c1">//
will configure test timeout, description, etc.</span>
+
+ <span class="nd">@Test</span>
+ <span class="kd">public</span> <span class="kt">void</span> <span
class="nf">testCreateNode</span><span class="o">()</span> <span
class="o">{</span>
+ <span class="n">SlingClient</span> <span class="n">client</span> <span
class="o">=</span> <span class="n">instanceRule</span><span
class="o">.</span><span class="na">getAdminClient</span><span
class="o">();</span>
+ <span class="n">client</span><span class="o">.</span><span
class="na">createNode</span><span class="o">(</span><span
class="s">"/content/myNode"</span><span class="o">,</span> <span
class="s">"nt:unstructured"</span><span class="o">);</span>
+ <span class="n">Assert</span><span class="o">.</span><span
class="na">assertTrue</span><span class="o">(</span><span class="s">"Node
should be there"</span><span class="o">,</span> <span
class="n">client</span><span class="o">.</span><span
class="na">exists</span><span class="o">(</span><span
class="s">"/content/myNode"</span><span class="o">));</span>
+ <span
class="c1">//client.adaptTo(OsgiConsoleClient.class).editConfigurationWithWait(10,
"MYPID", null, myMap);</span>
+ <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+</td></tr></table>
+
<h2 id="summary">Summary<a class="headerlink" href="#summary" title="Permanent
link">¶</a></h2>
<p>Combining the above testing techniques has worked well for us in creating
and testing Sling. Being able to test things at different levels of integration
has proved an efficient way to get good test coverage without having to write
too much boring test code.</p>
<div class="timestamp" style="margin-top: 30px; font-size: 80%;
text-align: right;">
- Rev. 1704519 by bdelacretaz on Tue, 22 Sep 2015 10:16:35 +0000
+ Rev. 1742262 by radu on Wed, 4 May 2016 12:39:56 +0000
</div>
<div class="trademarkFooter">
Apache Sling, Sling, Apache, the Apache feather logo, and the Apache
Sling project