fabric3
Content
Documentation
Developer Reference
Testing
Testing
search
attachments
weblink
advanced
image-effects
image-attributes
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
Colour picker
More colours
Formatting
Strikethrough
Subscript
Superscript
Monospace
Clear formatting
Bullet list
Numbered list
Task list
Outdent
Indent
Align left
Align center
Align right
Page layout
Link
Table
Insert
Insert content
Files and images
Link
Symbol
Emoticon
Markup
Horizontal rule
Insert macro
User mention
Jira Issue/Filter
Info
Status
Gallery
Table of Contents
Jira timeline
Lucidchart Diagrams
Trello Board
Other macros
Page layout
No layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Find/Replace
Keyboard shortcuts help
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account.
<p>Automated tests are a very useful way of improving code quality. They provide a context for development, documentation, and an on-going check of code correctness. These benefits give you the confidence to build on and refactor code knowing that it will continue to work as designed. This chapter covers the application testing facilities provided by Fabric3. Some familiarity with Ant, Maven, JUnit and mock objects are assumed.</p><h2>Unit Testing</h2><p>Java-based components in Fabric3 are in most cases simple POJOs with optional annotations. This means that this guide has little to add to the already well-covered topics of test-driven development and unit testing. It is important to note, however, that even with Fabric3's strong support for integration testing (examined below), it remains easier to find and fix a whole class of bugs by running lightweight tests as opposed to a (slower) test-harness.</p><h2>Integration Testing</h2><p>Fabric3 integration tests ensure that component implementations and composites provide the expected functionality and interact with other services and runtime resources in the expected way. They are referred to as 'itests'.</p><p>While Fabric3 does provide a lightweight standalone runtime environment, the recommended way to drive automated integration tests is through the specialized Gradle or Maven plugin. These handle the creation of an embedded Fabric3 runtime, deployment, and test execution. Fast runtime bootstrap and test execution makes iterative development easier. Since the Gradle and Maven plugins provide the same execution environment as the standalone server, component behavior verification can be done with little overhead. Use of the Gradle and Maven plugins also allows integration tests to be initiated in exactly the same way on development machines and the build server.</p><h2>JUnit Tests</h2><p>As detailed in the following sections, Fabric3 makes use of JUnit for writing in-container integration tests. Fabric3 provides a test runner that allows JUnit tests to act as components that can be injected with services to be test. When the build is run, the JUnit tests will be executed in a Fabric3 embedded container and their results reported as part of the test phase of the Maven or Gradle build. Writing a test component is simple - below is an example of how this is done:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=java" data-macro-schema-version="1" style="background-image: url(https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>@RunWith(Fabric3Runner.class) public class HelloWorldTest extends TestCase { @Reference protected HelloWorld helloWorld; public void testSayHello() { assertEquals("Hello, Foo", helloWorld.sayHello("Foo")); } }</pre></td></tr></table><p> </p><p><img class="editor-inline-macro" src="https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro?definition=e3BhZ2V0cmVlOnJvb3Q9QHNlbGZ9&locale=en_GB&version=2" data-macro-name="pagetree" data-macro-parameters="root=@self" data-macro-schema-version="1"></p>
Save
Close
Edit
Preview
View changes
Revert to last published version
{"serverDuration": 449, "requestCorrelationId": "061efce3a540467e84ee645754678015"}