incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Sling Website > Sling Testing Tools
Date Wed, 23 Mar 2011 11:10:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Sling+Testing+Tools">Sling
Testing Tools</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~bdelacretaz">Bertrand
Delacretaz</a>
    </h4>
        <br/>
                         <h4>Changes (3)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h1. Scriptable server-side
tests <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">TODO
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If
the [org.apache.sling.junit.scriptable|http://svn.apache.org/repos/asf/sling/trunk/testing/junit/scriptable]
bundle is active in a Sling system, (in addition to the {{org.apache.sling.junit.core}} bundle),
scriptable tests can be executed by the {{JUnitServlet}} according to the following rules:
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*
A node that has the {{sling:Test}} mixin is a scriptable test node. <br>* For security
reasons, scriptable test nodes are only executed as tests if they are found under {{/libs}}
or {{/apps}}, or more precisely under a path that&#39;s part of Sling&#39;s {{ResourceResolver}}
search path. <br>* To execute a test, the scriptable tests provider requests the test
node with a {{.test.txt}} selector and extension, and expects the output to contain only the
string {{TEST_PASSED}}. Empty lines and comment lines starting with a hash sign (#) are ignored
in the output. <br> <br>The [ScriptableTestsTest|http://svn.apache.org/repos/asf/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java]
class, from the integration test samples module described below, sets up such a test node
and its accompanying script, and calls the JUnitServlet to execute the test. It can be used
as a detailed example of how this works. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h1. Integration tests example <br>TODO
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>Sling provides a number of testing tools that enable the following use cases:</p>
<ul>
	<li>Run JUnit tests contributed by OSGi bundles in an OSGi system. This does not require
Sling, but works in Sling of course.</li>
	<li>Run scriptable tests in a Sling instance, using any supported scripting language.</li>
	<li>Run integration tests via HTTP against a Sling instance that is started during
the Maven build cycle.</li>
</ul>


<p>This pages describes those tools, and points to the bundles that implement them.</p>

<p>The <a href="http://svn.apache.org/repos/asf/sling/trunk/testing/samples/integration-tests"
class="external-link" rel="nofollow">testing/samples/integration-tests</a> module
demonstrates these tools, and is also meant as a sample project to show how to run integration
tests for Sling-based applications.</p>

<p>The main Sling integration tests at <a href="https://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests"
class="external-link" rel="nofollow">launchpad/integration-tests</a> were created
before this testing framework, and do not (as of March 2011) use it. The new testing tools
are simpler to use, but the "old" tests (all 400 of them as I write this) fulfill their validation
role for testing Sling itself, there's no real need to modify them to use the new tools.</p>

<h1><a name="SlingTestingTools-ServersideJUnittestscontributedbybundles"></a>Server-side
JUnit tests contributed by bundles</h1>
<p>The services provided by the <a href="http://svn.apache.org/repos/asf/sling/trunk/testing/junit/core"
class="external-link" rel="nofollow">org.apache.sling.junit.core</a> bundle allow
bundles to register JUnit tests, which are executed server-side by the JUnitServlet which
is registered by default at <tt>/system/sling/junit</tt>. This bundle is not dependent
on Sling, it should work in other OSGi contexts.</p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>JUnit servlet
security</b><br />Note that the JUnitServlet does not require authentication.
The servlet can be disabled by configuration if needed, but in general the <tt>/system</tt>
path should not be accessible to website visitors anyway.</td></tr></table></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>SlingJUnitServlet</b><br
/>For tighter integration with Sling, the alternate <tt>SlingJUnitServlet</tt>
is registered with the <tt>sling/junit/testing</tt> resource type and <tt>.junit</tt>
selector, if the bundle is running in a Sling system. Using this servlet instead of the plain
JUnitServlet also allows Sling authentication to be used for running the tests, and the standard
Sling request processing is used, including servlet filters for example.</td></tr></table></div>

<p>To try the JUnitServlet interactively, install the <a href="http://svn.apache.org/repos/asf/sling/trunk/testing/samples/sample-tests"
class="external-link" rel="nofollow">org.apache.sling.testing.samples.sampletests</a>
bundle.</p>

<p>This bundle contains a number of test classes, which are registered with the <tt>org.apache.sling.junit.core</tt>
services by way of the <tt>Sling-Test-Regexp=.*Test</tt> bundle header, defined
in the bundle's <tt>pom.xml</tt>. The JUnit core services use this regular expression
to select which classes of the test bundle should be executed as JUnit tests.</p>

<p>To list the available tests, open <a href="http://localhost:8080/system/sling/junit/"
class="external-link" rel="nofollow">http://localhost:8080/system/sling/junit/</a>
. The servlet shows available tests, and allows you to execute them via a POST request.</p>

<p>Adding a path allows you to select a specific subset of tests, as in <a href="http://localhost:8080/system/sling/junit/org.apache.sling.junit.remote.html"
class="external-link" rel="nofollow">http://localhost:8080/system/sling/junit/org.apache.sling.junit.remote.html</a>
- the example integration tests described below use this to selectively execute server-side
tests. The JUnitServlet provides various output formats, including in particular JSON, see
<a href="http://localhost:8080/system/sling/junit/.json" class="external-link" rel="nofollow">http://localhost:8080/system/sling/junit/.json</a>
for example.</p>

<p>Here's an example executing a few tests using curl:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Running tests with curl</b></div><div
class="codeContent panelContent">
<pre class="code-java">
$ curl -X POST http:<span class="code-comment">//localhost:8080/system/sling/junit/org.apache.sling.testing.samples.sampletests.JUnit.json
</span>[{
    <span class="code-quote">"INFO_TYPE"</span>: <span class="code-quote">"test"</span>,
    <span class="code-quote">"description"</span>: <span class="code-quote">"testPasses(org.apache.sling.testing.samples.sampletests.JUnit3Test)"</span>
  },{
    <span class="code-quote">"INFO_TYPE"</span>: <span class="code-quote">"test"</span>,
    <span class="code-quote">"description"</span>: <span class="code-quote">"testPasses(org.apache.sling.testing.samples.sampletests.JUnit4Test)"</span>
  },{
    <span class="code-quote">"INFO_TYPE"</span>: <span class="code-quote">"test"</span>,
    <span class="code-quote">"description"</span>: <span class="code-quote">"testRequiresBefore(org.apache.sling.testing.samples.sampletests.JUnit4Test)"</span>
  }
]
</pre>
</div></div>

<p>And another example with a test that fails:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Failing tests with curl</b></div><div
class="codeContent panelContent">
<pre class="code-java">
curl -X POST http:<span class="code-comment">//localhost:8080/system/sling/junit/org.apache.sling.testing.samples.failingtests.JUnit4FailingTest.json
</span>[{
    <span class="code-quote">"INFO_TYPE"</span>: <span class="code-quote">"test"</span>,
    <span class="code-quote">"description"</span>: <span class="code-quote">"testFailsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest)"</span>,
    <span class="code-quote">"failure"</span>: <span class="code-quote">"testFailsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest):
This JUnit4 test fails every time"</span>
  },{
    <span class="code-quote">"INFO_TYPE"</span>: <span class="code-quote">"test"</span>,
    <span class="code-quote">"description"</span>: <span class="code-quote">"testAssertsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest)"</span>,
    <span class="code-quote">"failure"</span>: <span class="code-quote">"testAssertsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest):
This JUnit4 test asserts every time"</span>
  }
]
</pre>
</div></div>

<h1><a name="SlingTestingTools-Scriptableserversidetests"></a>Scriptable
server-side tests</h1>
<p>If the <a href="http://svn.apache.org/repos/asf/sling/trunk/testing/junit/scriptable"
class="external-link" rel="nofollow">org.apache.sling.junit.scriptable</a> bundle
is active in a Sling system, (in addition to the <tt>org.apache.sling.junit.core</tt>
bundle), scriptable tests can be executed by the <tt>JUnitServlet</tt> according
to the following rules:</p>

<ul>
	<li>A node that has the <tt>sling:Test</tt> mixin is a scriptable test
node.</li>
	<li>For security reasons, scriptable test nodes are only executed as tests if they
are found under <tt>/libs</tt> or <tt>/apps</tt>, or more precisely
under a path that's part of Sling's <tt>ResourceResolver</tt> search path.</li>
	<li>To execute a test, the scriptable tests provider requests the test node with a
<tt>.test.txt</tt> selector and extension, and expects the output to contain only
the string <tt>TEST_PASSED</tt>. Empty lines and comment lines starting with a
hash sign (#) are ignored in the output.</li>
</ul>


<p>The <a href="http://svn.apache.org/repos/asf/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java"
class="external-link" rel="nofollow">ScriptableTestsTest</a> class, from the integration
test samples module described below, sets up such a test node and its accompanying script,
and calls the JUnitServlet to execute the test. It can be used as a detailed example of how
this works.</p>

<h1><a name="SlingTestingTools-Integrationtestsexample"></a>Integration
tests example</h1>
<p>TODO</p>

<h1><a name="SlingTestingTools-Remotetestexecution"></a>Remote test execution</h1>
<p>TODO</p>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Sling+Testing+Tools">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=26116321&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Sling+Testing+Tools?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message