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 10:54: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. Server-side JUnit tests
contributed by bundles <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;">The
services provided by the [org.apache.sling.junit.core|http://svn.apache.org/repos/asf/sling/trunk/testing/junit/core]
bundle allow bundles to register JUnit tests, which are executed server-side by the JUnitServlet
which is registered by default at {{/system/sling/junit}}. This bundle is not dependent on
Sling, it should work in other OSGi contexts. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{warning:title=JUnit
servlet security} <br>Note that the JUnitServlet does not require authentication. The
servlet can be disabled by configuration if needed, but in general the {{/system}} path should
not be accessible to website visitors anyway. <br>{warning} <br> <br>{note:title=SlingJUnitServlet}
<br>For tighter integration with Sling, the alternate {{SlingJUnitServlet}} is registered
with the {{sling/junit/testing}} resource type and {{.junit}} 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. <br>{note} <br> <br>To try
the JUnitServlet interactively, install the [org.apache.sling.testing.samples.sampletests|http://svn.apache.org/repos/asf/sling/trunk/testing/samples/sample-tests]
bundle. <br> <br>This bundle contains a number of test classes, which are registered
with the {{org.apache.sling.junit.core}} services by way of the {{Sling-Test-Regexp=.*Test}}
bundle header, defined in the bundle&#39;s {{pom.xml}}. The JUnit core services use this
regular expression to select which classes of the test bundle should be executed as JUnit
tests. <br> <br>To list the available tests, open http://localhost:8080/system/sling/junit/
. The servlet shows available tests, and allows you to execute them via a POST request. <br>
<br>Adding a path allows you to select a specific subset of tests, as in http://localhost:8080/system/sling/junit/org.apache.sling.junit.remote.html
- 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
http://localhost:8080/system/sling/junit/.json for example. <br> <br>Here&#39;s
an example executing a few tests using curl: <br> <br>{code:title=Running tests
with curl} <br>$ curl -X POST http://localhost:8080/system/sling/junit/org.apache.sling.testing.samples.sampletests.JUnit.json
<br>[{ <br>    &quot;INFO_TYPE&quot;: &quot;test&quot;, <br>
   &quot;description&quot;: &quot;testPasses(org.apache.sling.testing.samples.sampletests.JUnit3Test)&quot;
<br>  },{ <br>    &quot;INFO_TYPE&quot;: &quot;test&quot;, <br>
   &quot;description&quot;: &quot;testPasses(org.apache.sling.testing.samples.sampletests.JUnit4Test)&quot;
<br>  },{ <br>    &quot;INFO_TYPE&quot;: &quot;test&quot;, <br>
   &quot;description&quot;: &quot;testRequiresBefore(org.apache.sling.testing.samples.sampletests.JUnit4Test)&quot;
<br>  } <br>] <br>{code} <br> <br>And another example with a
test that fails: <br>{code:title=Failing tests with curl} <br>curl -X POST http://localhost:8080/system/sling/junit/org.apache.sling.testing.samples.failingtests.JUnit4FailingTest.json
<br>[{ <br>    &quot;INFO_TYPE&quot;: &quot;test&quot;, <br>
   &quot;description&quot;: &quot;testFailsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest)&quot;,
<br>    &quot;failure&quot;: &quot;testFailsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest):
This JUnit4 test fails every time&quot; <br>  },{ <br>    &quot;INFO_TYPE&quot;:
&quot;test&quot;, <br>    &quot;description&quot;: &quot;testAssertsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest)&quot;,
<br>    &quot;failure&quot;: &quot;testAssertsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest):
This JUnit4 test asserts every time&quot; <br>  } <br>] <br>{code} <br>
<br></td></tr>
            <tr><td class="diff-unchanged" >h1. Scriptable server-side tests <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>TODO</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=2&originalVersion=1">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