You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by janandith jayawardena <ja...@gmail.com> on 2008/05/28 21:03:43 UTC
How can I write automated tests.
Hi all ,
I would like to write test cases (Automated tests) for the scala module as I
code.
Can you guide me how to write automated tests.
And are these tests performed in maven while building or can I run them
separately.
If some of the tests fail in maven build but the module gets built and loads
in the launchpad as a bundle what will be the effect ?
janandith.
Re: How can I write automated tests.
Posted by Felix Meschberger <fm...@gmail.com>.
Hi Janandith,
Am Donnerstag, den 29.05.2008, 00:33 +0530 schrieb janandith
jayawardena:
> Hi all ,
>
> I would like to write test cases (Automated tests) for the scala module as I
> code.
>
> Can you guide me how to write automated tests.
The best thing to do is to have unit tests. You create the in the
src/test/java folder (paralells the src/main/java folder but for test
cases -- these will not be packaged into the final artifact).
If maven finds tests in src/test/java, these are automatically run when
building the project. By default the build fails if any of the tests
fails, which is a good thing IMHO.
Maven supports multiple test frameworks, within Sling we use JUnit. Any
test case your write is a class which extends from org.junit.TestCase.
Each public method prefixes with "test" -- e.g. testSomething -- is
automatically run by JUnit.
For more hints you might want to refer to existing unit tests, e.g. in
the jcr/resource bundle. These tests there also depend on the
commons/testing module, which contains some common helpers for creating
test cases.
>
> And are these tests performed in maven while building or can I run them
> separately.
Yes, maven runs them automatically provided they are in the right place
-- src/test/java by default.
>
> If some of the tests fail in maven build but the module gets built and loads
> in the launchpad as a bundle what will be the effect ?
Module The Maven build fails if any of the tests fail.
Regards
Felix
Re: How can I write automated tests.
Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Janandith,
On Wed, May 28, 2008 at 9:03 PM, janandith jayawardena
<ja...@gmail.com> wrote:
> ...I would like to write test cases (Automated tests) for the scala module as I
> code....
The best might be to study the scripting/javascript module, which
implements the Rhino-based javascript engine for Sling.
That module contains test code in src/test, which can be executed by
running "mvn test" in the scripting/javascript source code folder.
Most of our tests are written in JUnit 3 style, but the JUnit 4
libraries are used when testing, so feel free to use the improved
JUnit 4 features if needed.
The tests are also automatically executed when running "mvn install",
and if they fail the module is not installed in the Maven repository.
That can be disabled by using "-Dmaven.test.skip=true" as an option
for mvn.
To get started, it might be interesting for your to create a dummy
scripting engine, that does not really execute scripts but only
outputs their contents, for example. That would show you how to "wire"
a scripting engine in Sling, and take this part out of the equation
for implementing the actual Scala engine. This shouldn't be too hard
to do based on the scripting/javascript example, and we could use that
code as documentation for how to integrate new scripting engines.
-Bertrand