You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/05/17 17:06:26 UTC

[2/2] isis git commit: ISIS-1133: adocs for testing chapter.

ISIS-1133: adocs for testing chapter.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/6176226b
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/6176226b
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/6176226b

Branch: refs/heads/master
Commit: 6176226b69166c9483d399f14fa66fd7d93e3a91
Parents: ec058a8
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Sun May 17 16:02:36 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Sun May 17 16:02:36 2015 +0100

----------------------------------------------------------------------
 .../user-guide/_user-guide_testing.adoc         |   4 -
 .../_user-guide_testing_bdd-spec-support.adoc   | 355 +------------------
 ...de_testing_bdd-spec-support_bdd-tooling.adoc |  13 +
 ...e_testing_bdd-spec-support_how-it-works.adoc |  19 +
 ...de_testing_bdd-spec-support_key-classes.adoc |  58 +++
 ...ng_bdd-spec-support_maven-configuration.adoc |  72 ++++
 ...ing_bdd-spec-support_writing-a-bdd-spec.adoc | 140 ++++++++
 .../_user-guide_testing_fixture-scripts.adoc    |  98 ++---
 ...e_testing_fixture-scripts_api-and-usage.adoc | 285 +++++++++++++++
 ...de_testing_fixture-scripts_sudo-service.adoc |  58 +++
 .../_user-guide_testing_integ-test-support.adoc |   3 -
 ..._integ-test-support_maven-configuration.adoc |  29 +-
 ...ting_integ-test-support_wrapper-factory.adoc |   2 +-
 .../_user-guide_testing_overview.adoc           |  81 +++--
 .../_user-guide_testing_unit-test-support.adoc  | 219 +-----------
 ...esting_unit-test-support_contract-tests.adoc | 169 +++++++++
 ...ting_unit-test-support_jmock-extensions.adoc |  58 +++
 ...g_unit-test-support_maven-configuration.adoc |  45 +++
 .../testing/fixture-scripts/composite.png       | Bin 0 -> 24021 bytes
 .../images/testing/fixture-scripts/flat-1.png   | Bin 0 -> 22627 bytes
 .../images/testing/fixture-scripts/flat-2.png   | Bin 0 -> 10212 bytes
 .../organizing-fixture-scripts.pptx             | Bin 0 -> 56572 bytes
 .../prompt-specifying-number.png                | Bin 0 -> 53895 bytes
 .../images/testing/fixture-scripts/prompt.png   | Bin 0 -> 52869 bytes
 .../fixture-scripts/prototyping-menu.png        | Bin 0 -> 48699 bytes
 .../result-list-specifying-number.png           | Bin 0 -> 63100 bytes
 .../testing/fixture-scripts/result-list.png     | Bin 0 -> 50272 bytes
 .../main/asciidoc/user-guide/user-guide.adoc    |  28 +-
 28 files changed, 1061 insertions(+), 675 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing.adoc
index 3566e62..7acc994 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing.adoc
@@ -9,12 +9,8 @@ If you are going to use Apache Isis for developing complex business-critical app
 
 
 include::_user-guide_testing_overview.adoc[leveloffset=+1]
-
 include::_user-guide_testing_unit-test-support.adoc[leveloffset=+1]
-
 include::_user-guide_testing_integ-test-support.adoc[leveloffset=+1]
-
 include::_user-guide_testing_bdd-spec-support.adoc[leveloffset=+1]
-
 include::_user-guide_testing_fixture-scripts.adoc[leveloffset=+1]
 

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support.adoc
index 36cff34..68569c1 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support.adoc
@@ -3,358 +3,19 @@
 :_basedir: ../
 :_imagesdir: images/
 
-IMPORTANT: TODO
 
+link:http://en.wikipedia.org/wiki/Behavior-driven_development[Behaviour-driven design] (BDD) redefines testing not as an after-the-fact "let's check the system works", but rather as a means to work with the domain expert to (a) specify the behaviour of the feature _before_ starting implementation, and (b) provide a means that the domain expert can verify the feature after it has been implemented.
 
+Since domain experts are usually non-technical (at least, they are unlikely to be able to read or want to learn how to read JUnit/Java code), then applying BDD typically requires writing specifications in using structured English text and (ASCII) tables.  The BDD tooling parses this text and uses it to actually interact with the system under test.  As a byproduct the BDD frameworks generate readable output of some form; this is often an annotated version of the original specification, marked up to indicate which specifications passed, which have failed.  This readable output is a form of "living documentation"; it captures the actual behaviour of the system, and so is guaranteed to be accurate.
 
-== Concepts
+There are many BDD tools out there; Apache Isis provides an integration with link:https://cucumber.io/docs/reference/jvm#java[Cucumber JVM] (see also the https://github.com/cucumber/cucumber-jvm[github site]):
 
-The `isis-core-specsupport` and `isis-core-integtestsupport` modules provide the ability to bootstrap Isis and run either BDD specifications
-or regular integration tests.
 
-*
 
-In the case of BDD specs, these are run using https://github.com/cucumber/cucumber-jvm[Cucumber-JVM], the Java port of the original Ruby http://cukes.info[Cucumber] tool.
+include::_user-guide_testing_bdd-spec-support_how-it-works.adoc[leveloffset=+1]
+include::_user-guide_testing_bdd-spec-support_key-classes.adoc[leveloffset=+1]
+include::_user-guide_testing_bdd-spec-support_writing-a-bdd-spec.adoc[leveloffset=+1]
+include::_user-guide_testing_bdd-spec-support_bdd-tooling.adoc[leveloffset=+1]
+include::_user-guide_testing_bdd-spec-support_maven-configuration.adoc[leveloffset=+1]
 
-Specifications are written in the https://github.com/cucumber/cucumber/wiki/Gherkin[Gherkin] DSL, following the https://github.com/cucumber/cucumber/wiki/Given-When-Then["given/when/then"] format. Cucumber-JVM itself is a JUnit runner, and searches for https://github.com/cucumber/cucumber/wiki/Feature-Introduction[feature files] on the classpath. These in turn are matched to http://cukes.info/step-definitions.html[step definition]s through regular expressions. It is the step definitions (the "glue") that exercise the system.
 
-*
-
-In the case of integration tests, these are run using JUnit.
-
-To untangle the above a little: in terms of lines of code to be written, the code that goes in step definitions is broadly the same as the code that goes in an integration test method. The benefit of the former is that the given/then/when scenarios feature file describe the context of the interaction, and the step definitions are reusable across scenarios.
-
-There are some key framework classes that make up the spec/integtest support; these are discussed below.
-
-=== IsisSystemForTest
-
-To support both BDD specs and integration tests, Isis provides the `IsisSystemForTest` class. This allows a complete running instance of Isis to be bootstrapped (usually with the JDO objectstore), and then held on a `ThreadLocal` from one test to another.
-
-Typically bootstrapping code is used to lazily instantiate the `IsisSystemForTest` once and once only. The mechanism for doing this is line-for-line identical in both BDD step defs and integration tests.
-
-=== ScenarioExecution
-
-Isis also provides a `ScenarioExecution` class. The purpose of this class is to provide a context under which the specification or an integration test is executing.
-
-For both BDD specs and integration tests, the `ScenarioExecution` also provides access to the configured domain services (accessible through the `service(...)` method) and the `DomainObjectContainer` (through the `container()` method).
-
-In addition, UI behaviour can be integration tested by "wrapping" each domain object in a proxy. This proxy ensures that the "see it/use it/do it" rules (ie to hide, disable, or validate) are enforced. The wrapping is performed using the `WrapperFactory`, part of the link:../reference/services/wrapper-factory.html[isis-core-wrapper] module. The `ScenarioExecution`'s `wrap()` and `unwrap()` helper methods provide access to this capability.
-
-The `ScenarioExecution` also provides the `install()` method, allowing fixtures to be installed in the normal way. If using the JDO Object store, then these fixtures the `IsisJdoSupport` service can be used to run arbitrary SQL against the underlying database (eg to truncate/delete existing tables as need be).
-
-Of relevance only to BDD specs, the `ScenarioExecution`'s `getVar()` and `putVar()` methods also allow variables to be passed from one step definition to the next. (Broadly speaking, this is the same as the "World" object in Ruby-flavoured Cucumber).
-
-Like the `IsisSystemForTest` class, the `ScenarioExecution` class also binds an instance of itself onto a `ThreadLocal`. It can then be accessed in both BDD step defs and in integration tests using `ScenarioExecution.current()` static method.
-
-=== CukeGlueAbstract and IntegrationTestAbstract
-
-The `CukeGlueAbstract` acts as a convenience superclass for writing BDD step definitions. Similarly, the `IntegrationTestAbstract` acts as a convenience subclass for writing integration tests. These two classes are very similar in that they both delegate to an underlying `ScenarioExecution`.
-
-=== Separate Glue from Specs
-
-The "glue" (step definitions) are intended to be reused across features. We therefore recommend that they reside in a separate package, and are organized by the entity type upon which they act.
-
-For example, given a feature that involves `Customer` and `Order`, have the step definitions pertaining to `Customer` reside in `CustomerGlue`, and the step definitions pertaining to `Order` reside in `OrderGlue`.
-
-The Cucumber-JVM spec runner allows you to indicate which package(s) should be recursively searched to find any glue.
-
-=== Integration- vs Unit- Scope
-
-Although BDD specs are most commonly used for end-to-end tests (ie at the same scope as an integration test), the two concerns (expressability of a test to a business person vs granularity of the test) should not be conflated. There are a couple of http://silkandspinach.net/2013/01/18/a-testing-strategy/[good] blog http://claysnow.co.uk/the-testing-iceberg/[posts] discussing http://claysnow.co.uk/living-documentation-can-be-readable-and-fast/[this]. The basic idea is to avoid the overhead of a heavy-duty integration test if possible.
-
-Isis takes inspiration from these to optionally allow BDD specs to be run at a unit scope. The scope is indicated by annotating the scenario with the `@unit` or `@integration` tags.
-
-When running under unit-level scope, the Isis system is _not_ instantiated. Instead, `ScenarioExecution` class returns JMock mocks (except for the `WrapperFactory`, if configured).
-
-Writing a BDD spec that supports both modes of operation therefore takes more effort, but the benefit is a (much) faster executing test suite. Writing to support both modes means that the developer/tester can easily check the scenario at both scopes just by altering the tag.
-
-To support unit-testing, Isis provides the `InMemoryDB` class; a glorified hashmap of "persisted" objects. Use of this utility class is optional.
-
-== Usage
-
-The following examples are taken from the https://github.com/apache/isis/tree/master/example/application/todoapp[todoapp]; in particular from that project's https://github.com/apache/isis/tree/master/example/application/todoapp/integtests/src/test/java[integration test] module.
-
-=== Root pom
-
-In the root https://github.com/apache/isis/blob/master/example/application/todoapp/pom.xml[`pom.xml`], we recommend that you update the `maven-surefire-plugin` patterns, so that BDD specs are recognised alongside unit and integration tests:
-
-[source]
-----
-<plugin>
-    <groupId>org.apache.maven.plugins</groupId>
-    <artifactId>maven-surefire-plugin</artifactId>
-    <version>2.10</version>
-    <configuration>
-        <includes>
-            <include>**/*Test.java</include>
-            <include>**/*Test_*.java</include>
-            <include>**/*Spec*.java</include>
-        </includes>
-        <excludes>
-            <exclude>**/Test*.java</exclude>
-            <exclude>**/*ForTesting.java</exclude>
-            <exclude>**/*Abstract*.java</exclude>
-        </excludes>
-        <useFile>true</useFile>
-        <printSummary>true</printSummary>
-        <outputDirectory>${project.build.directory}/surefire-reports</outputDirectory>
-    </configuration>
-</plugin>
-----
-
-=== Integration testing module
-
-Assuming you have a module for your integration tests, add in the dependencies:
-
-[source]
-----
-<dependency>
-    <groupId>org.apache.isis.core</groupId>
-    <artifactId>isis-core-specsupport</artifactId>
-</dependency>
-<dependency>
-    <groupId>org.apache.isis.core</groupId>
-    <artifactId>isis-core-integtestsupport</artifactId>
-</dependency>
-----
-
-There is no need to explicitly add in a dependency on `isis-core-wrapper`; this is done automatically.
-
-=== Writing an Integration test
-
-Integration tests should subclass from `IntegrationTestAbstract`. For example, here's a the https://github.com/apache/isis/blob/master/example/application/todoapp/integtests/src/test/java/integration/tests/actions/ToDoItemTest_completed.java[`ToDoItemTest_completed`] test which exercises of the `ToDoItem`'s `completed()` action:
-
-[source]
-----
-public class ToDoItemTest_completed  {
-
-    @BeforeClass
-    public static void initClass() {
-        PropertyConfigurator.configure("logging.properties");
-        ToDoSystemInitializer.initIsft();
-
-        // instantiating will install onto ThreadLocal
-        new ScenarioExecutionForIntegration();
-    }
-
-    private ToDoItem toDoItem;
-
-    @Before
-    public void setUp() throws Exception {
-        scenarioExecution().install(new ToDoItemsFixture());
-
-        final List<ToDoItem> all = wrap(service(ToDoItems.class)).notYetComplete();
-        toDoItem = wrap(all.get(0));
-    }
-
-    @Test
-    public void happyCase() throws Exception {
-        assertThat(toDoItem.isComplete(), is(false));
-        toDoItem.completed();
-        assertThat(toDoItem.isComplete(), is(true));
-    }
-
-    @Test
-    public void cannotCompleteIfAlreadyCompleted() throws Exception {
-        unwrap(toDoItem).setComplete(true);
-        expectedExceptions.expectMessage("Already completed");
-        toDoItem.completed();
-    }
-
-    @Test
-    public void cannotSetPropertyDirectly() throws Exception {
-        expectedExceptions.expectMessage("Always disabled");
-        toDoItem.setComplete(true);
-    }
-}
-----
-
-The https://github.com/apache/isis/blob/master/example/application/todoapp/fixture/src/main/java/fixture/todo/ToDoItemsFixture.java[ToDoItemsFixture] referenced above tears down data as well as installs new data. In this example it runs at the class level (`@BeforeClass`), but it can also run at the instance level (`@Before`).
-
-Note also that when the `ToDoItem` is wrapped, it is not possible to call `setComplete()` directly on the object; but when it is unwrapped then this call can be made as per normal.
-
-The https://github.com/apache/isis/blob/master/example/application/todoapp/integtests/src/test/java/integration/ToDoSystemInitializer.java[ToDoSystemInitializer] class referenced above is responsible for setting up the `IsisSystemForTest`. You can think of it as being broadly equivalent to the information that is in the regular `isis.properties` file:
-
-[source]
-----
-public class ToDoSystemInitializer {
-
-    public static IsisSystemForTest initIsft() {
-        IsisSystemForTest isft = IsisSystemForTest.getElseNull();
-        if(isft == null) {
-            isft = new ToDoSystemBuilder().build().setUpSystem();
-            IsisSystemForTest.set(isft);
-        }
-        return isft;
-    }
-
-    private static class ToDoSystemBuilder extends IsisSystemForTest.Builder {
-        public ToDoSystemBuilder() {
-            withLoggingAt(Level.INFO);
-            with(testConfiguration());
-            with(new DataNucleusPersistenceMechanismInstaller());
-            withServices(
-                    new ToDoItemsJdo(),
-                    new WrapperFactoryDefault(),
-                    new RegisterEntities(),
-                    new IsisJdoSupportImpl()
-                    );
-        }
-
-        private IsisConfiguration testConfiguration() {
-            // ... elided ...
-        }
-    }
-}
-----
-
-=== Writing a BDD specification
-
-BDD specifications contain a few more parts:
-
-*
-
-a `XxxSpec.feature` file, describing the feature and the scenarios (given/when/then)s that constitute its acceptance criteria
-
-*
-
-a `RunSpecs.java` class file to run the specification (all boilerplate). This will run all `.feature` files in the same package or subpackages.
-
-*
-
-one or several `XxxGlue` constituting the step definitions to be matched against. These are normally placed in a separate package(s) to the specifications; the `glue` attribute of the Cucumber-JVM JUnit runner indicates which package(s) to search in.
-
-*
-
-a system initializer class. This can be reused with any integration tests (eg the `ToDoSystemInitializer` class, shown above).
-
-You may find it more convenient to place the `.feature` files in `src/test/java`, rather than `src/test/resources`. If you wish to do this, then your integration test module's `pom.xml` must contain:
-
-[source]
-----
-<build>
-    <testResources>
-        <testResource>
-            <filtering>false</filtering>
-            <directory>src/test/resources</directory>
-        </testResource>
-        <testResource>
-            <filtering>false</filtering>
-            <directory>src/test/java</directory>
-            <includes>
-                <include>**</include>
-            </includes>
-            <excludes>
-                <exclude>**/*.java</exclude>
-            </excludes>
-        </testResource>
-    </testResources>
-</build>
-----
-
-Let's now look at the a specification for the `ToDoItem&#39;`s "completed" feature. Firstly, the https://github.com/apache/isis/blob/master/example/application/todoapp/integtests/src/test/java/integration/specs/todoitem/ToDoItemSpec_findAndComplete.feature[`ToDoItemSpec_findAndComplete.feature`]:
-
-[source]
-----
-@ToDoItemsFixture
-Feature: Find And Complete ToDo Items
-
-    @integration
-    Scenario: Todo items once completed are no longer listed
-      Given there are a number of incomplete ToDo items
-      When  I choose the first of the incomplete items
-      And   mark the item as complete
-      Then  the item is no longer listed as incomplete
-----
-
-The `@ToDoItemsFixture` is a custom tag we've specified to indicate the prerequisite fixtures to be loaded; more on this in a moment. The `@integration` tag, meanwhile, says that this feature should be run with integration-level scope. (If we wanted to run at unit-level scope, the tag would be `@unit`).
-
-The https://github.com/apache/isis/blob/master/example/application/todoapp/integtests/src/test/java/integration/specs/todoitem/RunSpecs.java[`RunSpecs`] class to run this feature (and any other features in this package or subpackages) is just boilerplate:
-
-[source]
-----
-@RunWith(Cucumber.class)
-@Cucumber.Options(
-        format = {
-                "html:target/cucumber-html-report",
-                "json:target/cucumber.json"
-        },
-        glue={"classpath:com.mycompany.integration.glue"},
-        strict = true,
-        tags = { "~@backlog", "~@ignore" })
-public class RunSpecs {
-    // intentionally empty
-}
-----
-
-The JSON formatter allows integration with enhanced reports, for example as provided by http://www.masterthought.net/section/cucumber-reporting[Masterthought.net] (screenshots at end of page). (Commented out) configuration for this is provided in the link:../intro/getting-started/simpleapp-archetype.html[simpleapp] `integtests` module's https://github.com/apache/isis/blob/07fe61ef3fb029ae36427f60da2afeeb931e4f88/example/application/simpleapp/integtests/pom.xml#L52[pom.xml].
-
-The bootstrapping of Isis can be moved into a https://github.com/apache/isis/blob/07fe61ef3fb029ae36427f60da2afeeb931e4f88/example/application/simpleapp/integtests/src/test/java/domainapp/integtests/specglue/BootstrappingGlue.java#L26[`BootstrappingGlue`] step definition:
-
-[source]
-----
-public class BootstrappingGlue extends CukeGlueAbstract {
-
-    @Before(value={"@integration"}, order=100)
-    public void beforeScenarioIntegrationScope() {
-        PropertyConfigurator.configure("logging.properties");
-        SimpleAppSystemInitializer.initIsft();
-
-        before(ScenarioExecutionScope.INTEGRATION);
-    }
-
-    @After
-    public void afterScenario(cucumber.api.Scenario sc) {
-        assertMocksSatisfied();
-        after(sc);
-    }
-
-    // bootstrapping of @unit scope omitted
-}
-----
-
-The fixture to run also lives in its own step definition, https://github.com/apache/isis/blob/07fe61ef3fb029ae36427f60da2afeeb931e4f88/example/application/simpleapp/integtests/src/test/java/domainapp/integtests/specglue/CatalogOfFixturesGlue.java#L24[`CatalogOfFixturesGlue`]:
-
-[source]
-----
-public class CatalogOfFixturesGlue extends CukeGlueAbstract {
-
-    @Before(value={"@integration", "@SimpleObjectsFixture"}, order=20000)
-    public void integrationFixtures() throws Throwable {
-        scenarioExecution().install(new RecreateSimpleObjects());
-    }
-
-}
-----
-
-Note that this is annotated with a tag (`@SimpleObjectsFixture`) so that the correct fixture runs. (We might have a whole variety of these).
-
-The step definitions pertaining to `SimpleObject` domain entity then reside in the https://github.com/apache/isis/blob/07fe61ef3fb029ae36427f60da2afeeb931e4f88/example/application/simpleapp/integtests/src/test/java/domainapp/integtests/specglue/modules/simple/SimpleObjectGlue.java#L31[`SimpleObjectGlue`] class. This is where the heavy lifting gets done:
-
-[source]
-----
-public class SimpleObjectGlue extends CukeGlueAbstract {
-
-    @Given("^there are.* (\\d+) simple objects$")
-    public void there_are_N_simple_objects(int n) throws Throwable {
-        try {
-            final List<SimpleObject> findAll = service(SimpleObjects.class).listAll();
-            assertThat(findAll.size(), is(n));
-            putVar("list", "all", findAll);
-
-        } finally {
-            assertMocksSatisfied();
-        }
-    }
-
-    @When("^I create a new simple object$")
-    public void I_create_a_new_simple_object() throws Throwable {
-        service(SimpleObjects.class).create(UUID.randomUUID().toString());
-    }
-
-}
-----
-
-== BDD Tooling
-
-To help write feature files and generate step definitions, we recommend https://github.com/rlogiacco/Natural[Roberto Lo Giacco's Eclipse plugin]. For more information, see Dan's short http://danhaywood.com/2013/07/05/cucumber-editors-in-eclipse/[blog post]. It works very well. Of interest: this is implemented using http://www.eclipse.org/Xtext/[XText].
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_bdd-tooling.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_bdd-tooling.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_bdd-tooling.adoc
new file mode 100644
index 0000000..ede2b2a
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_bdd-tooling.adoc
@@ -0,0 +1,13 @@
+= BDD Tooling
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+
+
+To help write feature files and generate step definitions, we recommend https://github.com/rlogiacco/Natural[Roberto Lo Giacco's Eclipse plugin]. For more information, see Dan's short http://danhaywood.com/2013/07/05/cucumber-editors-in-eclipse/[blog post]. It works very well. Of interest: this is implemented using http://www.eclipse.org/Xtext/[XText].
+
+
+

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_how-it-works.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_how-it-works.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_how-it-works.adoc
new file mode 100644
index 0000000..27d0e49
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_how-it-works.adoc
@@ -0,0 +1,19 @@
+= How it works
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+At a high level, here's how Cucumber works
+
+* specifications are written in the https://github.com/cucumber/cucumber/wiki/Gherkin[Gherkin] DSL, following the https://github.com/cucumber/cucumber/wiki/Given-When-Then["given/when/then"] format.
+
+* Cucumber-JVM itself is a JUnit runner, and searches for https://github.com/cucumber/cucumber/wiki/Feature-Introduction[feature files] on the classpath.
+
+* These in turn are matched to http://cukes.info/step-definitions.html[step definition]s through regular expressions. +
++
+It is the step definitions (the "glue") that exercise the system.
+
+The code that goes in step definitions is broadly the same as the code that goes in an integration test method.  One benefit of using step definitions (rather than integration tests) is that the step definitions are reusable across scenarios, so there may be less code overall to maintain.  For example, if you have a step definition that maps to "given an uncompleted todo item", then this can be used for all the scenarios that start with that as their precondition.
+

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_key-classes.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_key-classes.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_key-classes.adoc
new file mode 100644
index 0000000..9244f6e
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_key-classes.adoc
@@ -0,0 +1,58 @@
+= Key classes
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+
+There are some key framework classes that make up the spec support; these are discussed below.
+
+NOTE: some of these are also used by Isis' <<_integration_test_support, Integration Test support>>.
+
+
+
+
+== `IsisSystemForTest`
+
+The `IsisSystemForTest` class allows a complete running instance of Isis to be bootstrapped (with the JDO objectstore); this is then held on a a `ThreadLocal` from one test to another.
+
+Typically bootstrapping code is used to lazily instantiate the `IsisSystemForTest` once and once only. The mechanism for doing this is line-for-line identical in both BDD step defs and integration tests.
+
+
+
+
+== `ScenarioExecution`
+
+The `ScenarioExecution` provides a context for a scenario that is being executed.  It is Cucumber that determines which step definitions are run, and in which order, and so state cannot be passed between step definitions using local variables or instance variables.  Instead the `ScenarioExecution` acts like a hashmap, allowing each step to put data (eg "given an uncompleted todoitem") into the map or get data ("when I complete the todoitem") from the map.  This is done using the `putVar(...)` and `getVar(...)` methods.
+
+[TIP]
+====
+This corresponds broadly to the "World" object in Ruby-flavoured Cucumber.
+====
+
+The `ScenarioExecution` also provids access to the configured domain services (using the `service(...)` method) and the `DomainObjectContainer` (through the `container()` method).
+
+[NOTE]
+====
+This could probably be refactored; Cucumber JVM provides automatic dependency injection into setp definitions, but Isis does not currently leverage or exploit this capability.
+====
+
+Like the `IsisSystemForTest` class, the `ScenarioExecution` class binds an instance of itself onto a `ThreadLocal`. It can then be accessed in BDD step definitions using `ScenarioExecution.current()` static method.
+
+
+
+== `WrapperFactory`
+
+As with integration tests, the UI can be simulated by "wrapping" each domain object in a proxy using the `WrapperFactory`.
+
+
+
+
+== `CukeGlueAbstract`
+
+The `CukeGlueAbstract` acts as a convenience superclass for writing BDD step definitions (analogous to the `IntegrationTestAbstract` for integation tests).  Underneath the covers it delegates to an underlying `ScenarioExecution`.
+
+
+
+

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_maven-configuration.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_maven-configuration.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_maven-configuration.adoc
new file mode 100644
index 0000000..88bbc7f
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_maven-configuration.adoc
@@ -0,0 +1,72 @@
+= Maven Configuration
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+
+Apache Isis' BDD spec support is automatically configured if you use the <<_simpleapp_archetype, SimpleApp archetype>>.  To set it up manually, update the `pom.xml` of your domain object model module:
+
+[source,xml]
+----
+<dependency>
+    <groupId>org.apache.isis.core</groupId>
+    <artifactId>isis-core-specsupport</artifactId>
+    <scope>test</scope> // <1>
+</dependency>
+----
+<1> Normally `test`; usual Maven scoping rules apply.
+
+
+We also recommend that you configure the `maven-surefire-plugin` to pick up the following class patterns:
+
+
+[source,xml]
+----
+<plugin>
+    <groupId>org.apache.maven.plugins</groupId>
+    <artifactId>maven-surefire-plugin</artifactId>
+    <version>2.10</version>
+    <configuration>
+        <includes>
+            <include>**/*Test.java</include>
+            <include>**/*Test_*.java</include>
+            <include>**/*Spec*.java</include>
+        </includes>
+        <excludes>
+            <exclude>**/Test*.java</exclude>
+            <exclude>**/*ForTesting.java</exclude>
+            <exclude>**/*Abstract*.java</exclude>
+        </excludes>
+        <useFile>true</useFile>
+        <printSummary>true</printSummary>
+        <outputDirectory>${project.build.directory}/surefire-reports</outputDirectory>
+    </configuration>
+</plugin>
+----
+
+
+You may also find it more convenient to place the `.feature` files in `src/test/java`, rather than `src/test/resources`.  If you wish to do this, then your integtest module's `pom.xml` must contain:
+
+[source]
+----
+<build>
+    <testResources>
+        <testResource>
+            <filtering>false</filtering>
+            <directory>src/test/resources</directory>
+        </testResource>
+        <testResource>
+            <filtering>false</filtering>
+            <directory>src/test/java</directory>
+            <includes>
+                <include>**</include>
+            </includes>
+            <excludes>
+                <exclude>**/*.java</exclude>
+            </excludes>
+        </testResource>
+    </testResources>
+</build>
+----

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_writing-a-bdd-spec.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_writing-a-bdd-spec.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_writing-a-bdd-spec.adoc
new file mode 100644
index 0000000..5cdc050
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_bdd-spec-support_writing-a-bdd-spec.adoc
@@ -0,0 +1,140 @@
+= Writing a BDD spec
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+
+BDD specifications contain:
+
+* a `XxxSpec.feature` file, describing the feature and the scenarios (given/when/then)s that constitute its acceptance criteria
+
+* a `RunSpecs.java` class file to run the specification (all boilerplate). This will run all `.feature` files in the same package or subpackages.
+
+* one or several `XxxGlue` constituting the step definitions to be matched against. +
++
+The "glue" (step definitions) are intended to be reused across features. We therefore recommend that they reside in a separate package, and are organized by the entity type upon which they act. +
++
+For example, given a feature that involves `Customer` and `Order`, have the step definitions pertaining to `Customer` reside in `CustomerGlue`, and the step definitions pertaining to `Order` reside in `OrderGlue`. +
++
+The `glue` attribute of the Cucumber-JVM JUnit runner eallows you to indicate which package(s) should be recursively searched to find any glue.
+
+* a system initializer class.  You can reuse the  system initializer from any integration tests (as described in <<_integration_test_support, Integration Test Support>>, bootstrapping section).
+
+
+Here's an example of a feature from the <<_simpleapp_archetype, SimpleApp archetype>>:
+
+[source]
+----
+@SimpleObjectsFixture
+Feature: List and Create New Simple Objects
+
+  @integration
+  Scenario: Existing simple objects can be listed and new ones created
+    Given there are initially 3 simple objects
+    When  I create a new simple object
+    Then  there are 4 simple objects
+----
+
+The `@SimpleObjectsFixture` is a custom tag we've specified to indicate the prerequisite fixtures to be loaded; more on this in a moment. The `@integration` tag, meanwhile, says that this feature should be run with integration-level scope.
+
+
+[NOTE]
+====
+Although BDD specs are most commonly used for end-to-end tests (ie at the same scope as an integration test), the two concerns (expressability of a test to a business person vs granularity of the test) should not be conflated. There are a couple of http://silkandspinach.net/2013/01/18/a-testing-strategy/[good] blog http://claysnow.co.uk/the-testing-iceberg/[posts] discussing http://claysnow.co.uk/living-documentation-can-be-readable-and-fast/[this]. The basic idea is to avoid the overhead of a heavy-duty integration test if possible.
+
+Apache Isis does also support running BDD specs in unit test mode; by annotating the scenario with the `@unit` (rather than `@integration` tag).  When running under unit-level scope, the Isis system is _not_ instantiated.  Instead, the `ScenarioExecution` class returns JMock mocks (except for the `WrapperFactory`, if configured).
+
+To support unit testing scope Isis provides the `InMemoryDB` class; a glorified hashmap of "persisted" objects.  Use of this utility class is optional.
+
+Writing a BDD spec that supports both modes of operation therefore takes more effort and we expect most users interested in BDD will use integration-testing scope; for these reasons we have chosen _not_ to include unit-testing support in the <<_simpleapp_archetype, SimpleApp archetype>>.  For those who do require faster-executing test suite, it's worthwhile knowing that Isis can support this.
+
+====
+
+
+The `RunSpecs` class to run this feature (and any other features in this package or subpackages) is just boilerplate
+
+[source,java]
+----
+@RunWith(Cucumber.class)
+@CucumberOptions(
+        format = {
+                "html:target/cucumber-html-report"
+                ,"json:target/cucumber.json"
+        },
+        glue={"classpath:domainapp.integtests.specglue"},
+        strict = true,
+        tags = { "~@backlog", "~@ignore" })
+public class RunSpecs {
+    // intentionally empty
+}
+----
+
+The JSON formatter allows integration with enhanced reports, for example as provided by http://www.masterthought.net/section/cucumber-reporting[Masterthought.net] (screenshots at end of page). (Commented out) configuration for this is provided in the <<_simpleapp_archetype, SimpleApp archetype>>.
+
+The bootstrapping of Isis can be moved into a `BootstrappingGlue` step definition:
+
+[source,java]
+----
+public class BootstrappingGlue extends CukeGlueAbstract {
+    @Before(value={"@integration"}, order=100)
+    public void beforeScenarioIntegrationScope() {
+        org.apache.log4j.PropertyConfigurator.configure("logging.properties");
+        SimpleAppSystemInitializer.initIsft();
+
+        before(ScenarioExecutionScope.INTEGRATION);
+    }
+    @After
+    public void afterScenario(cucumber.api.Scenario sc) {
+        assertMocksSatisfied();
+        after(sc);
+    }
+}
+----
+
+The fixture to run also lives in its own step definition, https://github.com/apache/isis/blob/07fe61ef3fb029ae36427f60da2afeeb931e4f88/example/application/simpleapp/integtests/src/test/java/domainapp/integtests/specglue/CatalogOfFixturesGlue.java#L24[`CatalogOfFixturesGlue`]:
+
+[source,java]
+----
+public class CatalogOfFixturesGlue extends CukeGlueAbstract {
+    @Before(value={"@integration", "@SimpleObjectsFixture"}, order=20000)
+    public void integrationFixtures() throws Throwable {
+        scenarioExecution().install(new RecreateSimpleObjects());
+    }
+}
+----
+
+Note that this is annotated with a tag (`@SimpleObjectsFixture`) so that the correct fixture runs. (We might have a whole variety of these).
+
+The step definitions pertaining to `SimpleObject` domain entity then reside in the https://github.com/apache/isis/blob/07fe61ef3fb029ae36427f60da2afeeb931e4f88/example/application/simpleapp/integtests/src/test/java/domainapp/integtests/specglue/modules/simple/SimpleObjectGlue.java#L31[`SimpleObjectGlue`] class. This is where the heavy lifting gets done:
+
+[source,java]
+----
+public class SimpleObjectGlue extends CukeGlueAbstract {
+    @Given("^there are.* (\\d+) simple objects$")
+    public void there_are_N_simple_objects(int n) throws Throwable {
+        try {
+            final List<SimpleObject> findAll = service(SimpleObjects.class).listAll();
+            assertThat(findAll.size(), is(n));
+            putVar("list", "all", findAll);
+
+        } finally {
+            assertMocksSatisfied();
+        }
+    }
+    @When("^I create a new simple object$")
+    public void I_create_a_new_simple_object() throws Throwable {
+        service(SimpleObjects.class).create(UUID.randomUUID().toString());
+    }
+}
+----
+
+[TIP]
+====
+If using Java 8, note that Cucumber JVM supports a link:https://cucumber.io/docs/reference/jvm#java-8-lambdas[simplified syntax using lambdas].
+====
+
+
+
+

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts.adoc
index d4d3ffe..adba36a 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts.adoc
@@ -3,63 +3,41 @@
 :_basedir: ../
 :_imagesdir: images/
 
-IMPORTANT: TODO
-
-
-## API and Usage
-
-IMPORTANT: TODO
-
-## SudoService (1.9.0-SNAPSHOT)
-
-Sometimes in our fixture scripts we want to perform a business action runnin as a particular user.  This might be for the usual reason - so that our fixtures accurately reflect the reality of the system with all business constraints enforced using the `WrapperFactory` - or more straightforwardly it might be simply that the action depends on the identity of the user invoking the action.
-
-An example of the latter case is in the link:[todoapp]'s `ToDoItem` class:
-
-[source,java]
-.Production code that depends on current user
-----
-public ToDoItem newToDo(
-        @Parameter(regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*") @ParameterLayout(named="Description")
-        final String description,
-        @ParameterLayout(named="Category")
-        final Category category,
-        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Subcategory")
-        final Subcategory subcategory,
-        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Due by")
-        final LocalDate dueBy,
-        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Cost")
-        final BigDecimal cost) {
-    return newToDo(description, category, subcategory, currentUserName(), dueBy, cost);
-}
-private String currentUserName() {
-    return container.getUser().getName(); // <1>
-}
-----
-<1> is the current user.
-
-The fixture for this can use the `SudoService` to run a block of code as a specified user:
-
-[source,java]
-.Fixture Script
-----
-final String description = ...
-final Category category = ...
-final Subcategory subcategory = ...
-final LocalDate dueBy = ...
-final BigDecimal cost = ...
-final Location location = ...
-
-toDoItem = sudoService.sudo(username,
-        new Callable<ToDoItem>() {
-            @Override
-            public ToDoItem call() {
-                final ToDoItem toDoItem = wrap(toDoItems).newToDo(
-                        description, category, subcategory, dueBy, cost);
-                wrap(toDoItem).setLocation(location);
-                return toDoItem;
-            }
-        });
-----
-
-Behind the scenes the `SudoService` simply talks to the `DomainObjectContainer` to override the user returned by the `getUser()` API.  It is possible to override both users and roles.
+
+
+When writing integration tests (and implementing the glue for BDD specs) it can be difficult to keep the "given" short; there could be a lot of prerequisite data that needs to exist before you can actually exercise your system.  Moreover, however we do set up that data, but we also want to do so in a way that is resilient to the system changing over time.
+
+On a very simple system you could probably get away with using SQL to insert directly into the database, or you could use a toolkit such as link:http://dbunit.sourceforge.net/howto.html[dbunit] to upload data from flat files.  Such approaches aren't particularly maintainable though.  If in the future the domain entities (and therefore corresponding database tables) change their structure, then all of those data sets will need updating.
+
+Even more significantly, there's no way to guarantee that the data that's being loaded is logically consistent with the business behaviour of the domain objects themselves.  That is, there's nothing to stop your test from putting data into the database that would be invalid if one attempted to add it through the app.
+
+The solution that Isis provides is a small library called *_fixture scripts_*.  A fixture script is basically a wrapper for executing arbitrary work, but that work almost always invoking a business action.
+
+[TIP]
+====
+If you want to learn more on this topic (with live coding!), check out this https://skillsmatter.com/skillscasts/5638-to-those-whom-much-is-given-much-is-expected[presentation] given at BDD Exchange 2014.
+====
+
+There is another benefit to Isis' fixture script approach; the fixtures can be (in prototyping mode) run from your application.  This means that fixture scripts can actually help all the way through the development lifecycle:
+
+* when specifying a new feature, you can write a fixture script to get the system into the "given" state, and then start exploring the required functionality with the domain expert actually _within_ the application +
++
+And if you can't write a fixture script for the story, it probably means that there's some prerequisite feature that needs implementing that you hadn't previously recognized
+
+* when the developer implements the story, s/he has a precanned script to run when they manually verify the functionality works
+
+* when the developer automates the story's acceptance test as an integration test, they already have the "given" part of the test implemented
+
+* when you want to pass the feature over to the QA/tester for additional manual exploratory testing, they have a fixture script to get them to a jumping off point for their explorations
+
+* when you want to demonstrate the implemented feature to your domain expert, your demo can use the fixture script so you don't bore your audience in performing lots of boring setup before getting to the actual feature
+
+* when you want to roll out training to your users, you can write fixture scripts as part of their training exercises
+
+
+The following  sections explain the API and how to go about using the API.
+
+
+include::_user-guide_testing_fixture-scripts_api-and-usage.adoc[leveloffset=+1]
+include::_user-guide_testing_fixture-scripts_sudo-service.adoc[leveloffset=+1]
+

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_api-and-usage.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_api-and-usage.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_api-and-usage.adoc
new file mode 100644
index 0000000..b2d1ba2
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_api-and-usage.adoc
@@ -0,0 +1,285 @@
+= API and Usage
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+There are two parts to using fixture scripts: the `FixtureScripts` domain service class, and the `FixtureScript` view model class, both being `abstract`.
+
+* The job of the `FixtureScripts` domain service is to locate all fixture scripts from the classpath and to let them be invoked, either from an integration test/BDD spec or from the UI of your Isis app.
+
+* With `FixtureScript` meanwhile you subclass for each of the scenarios that you want to define.  You can also subclass from `FixtureScript` to create helpers; more on this below.
+
+Let's look at `FixtureScripts` domain service in more detail first.
+
+== `FixtureScripts`
+
+In your code you subclass `FixtureScripts` domain service primarily just to specify which package to search for.  For example, here's the service that's generated by the <<_simpleapp_archetype, SimpleApp archetype>>:
+
+[source,java]
+----
+@DomainService
+@DomainServiceLayout(
+        menuBar = DomainServiceLayout.MenuBar.SECONDARY,           // <1>
+        named="Prototyping",                                       // <2>
+        menuOrder = "500"
+)
+public class DomainAppFixturesService extends FixtureScripts {     // <3>
+
+    public DomainAppFixturesService() {
+        super(
+            "domainapp",                                           // <4>
+            MultipleExecutionStrategy.EXECUTE);                    // <5>
+    }
+    @Override
+    public FixtureScript default0RunFixtureScript() {
+        return findFixtureScriptFor(RecreateSimpleObjects.class);  // <6>
+    }
+    @Override
+    public List<FixtureScript> choices0RunFixtureScript() {        // <7>
+        return super.choices0RunFixtureScript();
+    }
+}
+----
+<1> in the UI, render the on the right hand side (secondary) menu bar...
+<2> ... under the "Prototyping" menu
+<3> inherit from `org.apache.isis.applib.fixturescripts.FixtureScripts`
+<4> search for all fixture scripts under the "domainapp" package; in your code this would probably be "com.mycompany.myapp" or similar
+<5> if the same fixture script (class) is encountered more than once, then run anyway; more on this in <<Organizing Fixture scripts>>.
+<6> (optional) specify a default fixture script to run, in this case `RecreateSimpleObjects` fixture script (see below)
+<7> make all fixture scripts found available as a drop-down (by increasing the visibility of this method to `public`)
+
+
+Here's how the domain service looks like in the UI:
+
+image::{_imagesdir}testing/fixture-scripts/prototyping-menu.png[width="700px",link="{_imagesdir}testing/fixture-scripts/prototyping-menu.png"]
+
+
+and here's what the `runFixtureScript` action prompt looks like:
+
+image::{_imagesdir}testing/fixture-scripts/prompt.png[width="700px",link="{_imagesdir}testing/fixture-scripts/prompt.png"]
+
+
+when this is executed, the resultant objects (actually, instances of FixtureResult`) are shown in the UI:
+
+image::{_imagesdir}testing/fixture-scripts/result-list.png[width="700px",link="_imagesdir}testing/fixture-scripts/result-list.png"]
+
+
+
+If you had defined many fixture scripts then a drop-down might become unwieldy, in which case your code would probably override the `autoComplete...())` instead:
+
+[source,java]
+----
+    @Override
+    public List<FixtureScript> autoComplete0RunFixtureScript(final @MinLength(1) String searchArg) {
+        return super.autoComplete0RunFixtureScript(searchArg);
+    }
+
+----
+
+You are free, of course, to add additional "convenience" actions into it if you wish for the most commonly used/demo'd setups ; you'll find that the <<_simpleapp_archetype, SimpleApp archetype>> adds this additional action:
+
+[source,java]
+----
+    @Action(
+            restrictTo = RestrictTo.PROTOTYPING
+    )
+    @ActionLayout(
+            cssClassFa="fa fa-refresh"
+    )
+    @MemberOrder(sequence="20")
+    public Object recreateObjectsAndReturnFirst() {
+        final List<FixtureResult> run = findFixtureScriptFor(RecreateSimpleObjects.class).run(null);
+        return run.get(0).getObject();
+    }
+----
+
+Let's now look at the `FixtureScript` class, where there's a bit more going on.
+
+== `FixtureScript`
+
+A fixture script is ultimately just a block of code that can be executed, so it's up to you how you implement it to set up the system.  However, we strongly recommend that you use it to invoke actions on business objects, in essence to replay what a real-life user would have done.  That way, the fixture script will remain valid even if the underlying implementation of the system changes in the future.
+
+Here's the `RecreateSimpleObjects` fixture script from the <<_simpleapp_archetype, SimpleApp archetype>>:
+
+[source,java]
+----
+public class RecreateSimpleObjects extends FixtureScript {                   // <1>
+
+    public final List<String> NAMES = Collections.unmodifiableList(Arrays.asList(
+            "Foo", "Bar", "Baz", "Frodo", "Froyo",
+            "Fizz", "Bip", "Bop", "Bang", "Boo"));                           // <2>
+    public RecreateSimpleObjects() {
+        withDiscoverability(Discoverability.DISCOVERABLE);                   // <3>
+    }
+    private Integer number;                                                  // <4>
+    public Integer getNumber() { return number; }
+    public RecreateSimpleObjects setNumber(final Integer number) {
+        this.number = number;
+        return this;
+    }
+    private final List<SimpleObject> simpleObjects = Lists.newArrayList();   // <5>
+    public List<SimpleObject> getSimpleObjects() {
+        return simpleObjects;
+    }
+    @Override
+    protected void execute(final ExecutionContext ec) {          // <6>
+        // defaults
+        final int number = defaultParam("number", ec, 3);        // <7>
+        // validate
+        if(number < 0 || number > NAMES.size()) {
+            throw new IllegalArgumentException(
+                String.format("number must be in range [0,%d)", NAMES.size()));
+        }
+        // execute
+        ec.executeChild(this, new SimpleObjectsTearDown());      // <8>
+        for (int i = 0; i < number; i++) {
+            final SimpleObjectCreate fs =
+                new SimpleObjectCreate().setName(NAMES.get(i));
+            ec.executeChild(this, fs.getName(), fs);             // <9>
+            simpleObjects.add(fs.getSimpleObject());             // <10>
+        }
+    }
+}
+----
+<1> inherit from `org.apache.isis.applib.fixturescripts.FixtureScript`
+<2> a hard-coded list of values for the names.  Note that the http://github.com/isisaddons/isis-module-fakedata}[Isis addons' fakedata] module (non-ASF) could also have been used
+<3> whether the script is "discoverable"; in other words whether it should be rendered in the drop-down by the `FixtureScripts` service
+<4> input property: the number of objects to create, up to 10; for the calling test to specify, but note this is optional and has a default (see below).  It's important that a wrapper class is used (ie `java.lang.Integer`, not `int`)
+<5> output property: the generated list of objects, for the calling test to grab
+<6> the mandatory execute(...) API
+<7> the `defaultParam(...)` (inherited from `FixtureScript`) will default the `number` property (using Java's Reflection API) if none was specified
+<8> call another fixture script (`SimpleObjectsTearDown`) using the provided `ExecutionContext`.  Note that although the fixture script is a view model, it's fine to simply instantiate it (rather than using `DomainObjectContainer#newTransientInstance(...)`).
+<9> calling another fixture script (`SimpleObjectCreate`) using the provided `ExecutionContext`
+<10> adding the created object to the list, for the calling object to use.
+
+
+Because this script has exposed a "number" property, it's possible to set this from within the UI.  For example:
+
+image::{_imagesdir}testing/fixture-scripts/prompt.png[width="700px"]
+
+
+When this is executed, the framework will parse the text and attempt to reflectively set the corresponding properties on the fixture result.  So, in this case, when the fixture script is executed we actually get 6 objects created:
+
+image::{_imagesdir}testing/fixture-scripts/result-list.png[width="700px"]
+
+
+
+It's commonplace for one fixture script to call another.  In the above example this script called `SimpleObjectsTearDown` and `SimpleObjectCreate`.  Let's take a quick look at `SimpleObjectCreate`:
+
+[source,java]
+----
+public class SimpleObjectCreate extends FixtureScript {       // <1>
+
+    private String name;                                      // <2>
+    public String getName() { return name; }
+    public SimpleObjectCreate setName(final String name) {
+        this.name = name;
+        return this;
+    }
+    private SimpleObject simpleObject;                        // <3>
+    public SimpleObject getSimpleObject() {
+        return simpleObject;
+    }
+    @Override
+    protected void execute(final ExecutionContext ec) {       // <4>
+        String name = checkParam("name", ec, String.class);   // <5>
+        this.simpleObject = wrap(simpleObjects)               // <6>
+                                .create(name);                // <7>
+        ec.addResult(this, simpleObject);                     // <8>
+    }
+    @javax.inject.Inject
+    private SimpleObjects simpleObjects;                      // <9>
+}
+----
+<1> inherit from `org.apache.isis.applib.fixturescripts.FixtureScript`, as above
+<2> input property: name of the object; this time it is required
+<3> output property: the created simple object
+<4> the mandatory execute(...) API
+<5> the `checkParam(...)` (inherited from `FixtureScript`) will check that the "name" property has been populated (using Java's Reflection API) and throw an exception if not
+<6> wrap the injected `SimpleObjects` domain service (using the <<_wrapper_factory, `WrapperFactory`>>) to simulate interaction through the UI...
+<7> .. and actually create the object using the "create" business action of that service
+<8> add the resulting object to the execution context; this makes the object available to access if run from the UI
+<9> inject the domain service into the fixture script
+
+
+
+
+
+
+
+== Using within Tests
+
+Fixture scripts can be called from integration tests just the same way that fixture scripts can call one another.
+
+For example, here's an integration test from the <<_simpleapp_archetype, SimpleApp archetype>>:
+
+[source,java]
+----
+public class SimpleObjectIntegTest extends SimpleAppIntegTest {
+    @Inject
+    FixtureScripts fixtureScripts;                      // <1>
+    SimpleObject simpleObjectWrapped;
+    @Before
+    public void setUp() throws Exception {
+        // given
+        RecreateSimpleObjects fs =
+             new RecreateSimpleObjects().setNumber(1);  // <2>
+        fixtureScripts.runFixtureScript(fs, null);      // <3>
+
+        SimpleObject simpleObjectPojo =
+            fs.getSimpleObjects().get(0);               // <4>
+        assertThat(simpleObjectPojo).isNotNull();
+
+        simpleObjectWrapped = wrap(simpleObjectPojo);   // <5>
+    }
+    @Test
+    public void accessible() throws Exception {
+        // when
+        final String name = simpleObjectWrapped.getName();
+        // then
+        assertThat(name).isEqualTo(fs.NAMES.get(0));
+    }
+    ...
+}
+----
+<1> inject the `FixtureScripts` domain service (just like any other domain service)
+<2> instantiate the fixture script for this test, and configure
+<3> execute the fixture script
+<4> obtain the object under test from the fixture
+<5> wrap the object (to simulate being interacted with through the UI)
+
+
+
+== Organizing Fixture scripts
+
+There are lots of ways to organize fixture scripts, but we've used them as either:
+
+* a fairly flat style, eg as in the <<_simpleapp_archetype, SimpleApp archetype>>, also as in the http://github.com/isisaddons/isis-app-todoapp}[Isis addons' todoapp];
+
+* in a "composite pattern" style, eg as in the https://github.com/estatio/estatio/blob/ea20a6ce257acede50de6ce4fd2ff29713fcd689/estatioapp/fixture/src/main/java/org/estatio/fixture/invoice/InvoiceForLeaseItemTypeOfDiscountOneQuarterForOxfMiracle005.java#L66)[Estatio open source app].
+
+These two styles are probably best illustrated with, well, some illustrations.  Here's a fixture script in the "flat" style for setting up a customer with some orders, a number of which has been placed:
+
+image::{_imagesdir}testing/fixture-scripts/flat-1.png[width="700px",link="_imagesdir}testing/fixture-scripts/flat-1.png"]
+
+Notice how we have a single script that's in control of the overall process, and takes responsibility for passing data from one fixture script to the next.
+
+Here's a similar, simpler script, from the same fictional app, to set up two customers:
+
+image::{_imagesdir}testing/fixture-scripts/flat-2.png[width="500px",link="_imagesdir}testing/fixture-scripts/flat-2.png"]
+
+We can reuse the same fixture "customer" script, either calling it twice or (perhaps better) passing it an array of customer details to set up.
+
+With the composite style, we rely on each fixture script to set up its own prerequisites.  Thus:
+
+image::{_imagesdir}testing/fixture-scripts/composite.png[width="550px",link="_imagesdir}testing/fixture-scripts/composite.png"]
+
+Back in the earlier <<_fixturescripts, `FixtureScripts`>> section we noted the `MultipleExecutionStrategy` setting.  We can now explain the meaning of this: the enum value of `EXECUTE` is designed for the flat style (where every fixture script will be called), whereas the enum value of `IGNORE` is designed for the composite style, and ensures that any fixture scripts visited more than once (eg TearDown) are only every executed the first time.
+
+As already noted , the app generated by the <<_simpleapp_archetype, SimpleApp archetype>> uses the flat structure, and we feel that it's a better at separating out the "how" (how we set up some graph of domain objects into a known state, eg a customer with shipped placed orders and a newly placed order) from the "what" (what data should we actually use for the customer's name, say).
+
+The composite style tends to combine these, which one could argue does not separate responsibilities well enough.  On the other hand, one could also make an argument that the composite style is a good way to implement precanned personas, eg "Joe", the customer who has a newly placed order, from "Mary" customer who has none.
+
+
+

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_sudo-service.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_sudo-service.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_sudo-service.adoc
new file mode 100644
index 0000000..dea52eb
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_fixture-scripts_sudo-service.adoc
@@ -0,0 +1,58 @@
+= SudoService (1.9.0-SNAPSHOT)
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+Sometimes in our fixture scripts we want to perform a business action running as a particular user.  This might be for the usual reason - so that our fixtures accurately reflect the reality of the system with all business constraints enforced using the `WrapperFactory` - or more straightforwardly it might be simply that the action depends on the identity of the user invoking the action.
+
+An example of the latter case is in the (non-ASF) http://github.com/isisaddons/isis-app-todoapp}[Isis addons' todoapp]'s `ToDoItem` class:
+
+[source,java]
+.Production code that depends on current user
+----
+public ToDoItem newToDo(
+        @Parameter(regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*") @ParameterLayout(named="Description")
+        final String description,
+        @ParameterLayout(named="Category")
+        final Category category,
+        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Subcategory")
+        final Subcategory subcategory,
+        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Due by")
+        final LocalDate dueBy,
+        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Cost")
+        final BigDecimal cost) {
+    return newToDo(description, category, subcategory, currentUserName(), dueBy, cost);
+}
+private String currentUserName() {
+    return container.getUser().getName(); // <1>
+}
+----
+<1> is the current user.
+
+The fixture for this can use the `SudoService` to run a block of code as a specified user:
+
+[source,java]
+.Fixture Script
+----
+final String description = ...
+final Category category = ...
+final Subcategory subcategory = ...
+final LocalDate dueBy = ...
+final BigDecimal cost = ...
+final Location location = ...
+
+toDoItem = sudoService.sudo(username,
+        new Callable<ToDoItem>() {
+            @Override
+            public ToDoItem call() {
+                final ToDoItem toDoItem = wrap(toDoItems).newToDo(
+                        description, category, subcategory, dueBy, cost);
+                wrap(toDoItem).setLocation(location);
+                return toDoItem;
+            }
+        });
+----
+
+Behind the scenes the `SudoService` simply talks to the `DomainObjectContainer` to override the user returned by the `getUser()` API.  It is possible to override both users and roles.

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support.adoc
index c0073e3..f4d4cab 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support.adoc
@@ -15,11 +15,8 @@ We'll get to all that shortly, but let's start by taking a look at what a typica
 
 
 include::_user-guide_testing_integ-test-support_typical-usage.adoc[leveloffset=+1]
-
 include::_user-guide_testing_integ-test-support_bootstrapping.adoc[leveloffset=+1]
-
 include::_user-guide_testing_integ-test-support_wrapper-factory.adoc[leveloffset=+1]
-
 include::_user-guide_testing_integ-test-support_maven-configuration.adoc[leveloffset=+1]
 
 

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_maven-configuration.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_maven-configuration.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_maven-configuration.adoc
index 04af875..609c52b 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_maven-configuration.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_maven-configuration.adoc
@@ -4,9 +4,7 @@
 :_imagesdir: images/
 
 
-IMPORTANT: TODO
-
-To use, update the `pom.xml` (this is already configured by the <<_simpleapp_archetype, SimpleApp archetype>>) :
+Apache Isis' integration test support is automatically configured if you use the <<_simpleapp_archetype, SimpleApp archetype>>.  To set it up manually, update the `pom.xml` of your domain object model module:
 
 [source]
 ----
@@ -20,3 +18,28 @@ To use, update the `pom.xml` (this is already configured by the <<_simpleapp_arc
 </dependency>
 ----
 
+We also recommend that you configure the `maven-surefire-plugin` to pick up the following class patterns:
+
+[source,xml]
+----
+<plugin>
+    <groupId>org.apache.maven.plugins</groupId>
+    <artifactId>maven-surefire-plugin</artifactId>
+    <version>2.10</version>
+    <configuration>
+        <includes>
+            <include>**/*Test.java</include>
+            <include>**/*Test_*.java</include>
+            <include>**/*Spec*.java</include>
+        </includes>
+        <excludes>
+            <exclude>**/Test*.java</exclude>
+            <exclude>**/*ForTesting.java</exclude>
+            <exclude>**/*Abstract*.java</exclude>
+        </excludes>
+        <useFile>true</useFile>
+        <printSummary>true</printSummary>
+        <outputDirectory>${project.build.directory}/surefire-reports</outputDirectory>
+    </configuration>
+</plugin>
+----

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_wrapper-factory.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_wrapper-factory.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_wrapper-factory.adoc
index 61fef93..e1f0d74 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_wrapper-factory.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_integ-test-support_wrapper-factory.adoc
@@ -50,7 +50,7 @@ Customer wrappedCustomer = wrapperFactory.wrap(wrappedCustomer);
 ----
 
 
-Going the other way -- getting hold of the underlying (wrapped) domain object -- is just as easy; call `WrapperFactory#unwrap(...)`.
+Going the other way -- getting hold of the underlying (wrapped) domain object -- is just as easy; just call `WrapperFactory#unwrap(...)`.
 
 For example:
 

http://git-wip-us.apache.org/repos/asf/isis/blob/6176226b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_overview.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_overview.adoc b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_overview.adoc
index 4997d99..790c8bc 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_overview.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/_user-guide_testing_overview.adoc
@@ -16,13 +16,14 @@ Dependencies of that object are mocked out.  These are written by a developer an
 +
 These are tests that represent the acceptance criteria of some business story; their intent should make sense to the domain expert (even if the domain expert is "non-technical")
 
-To put it another way: integration tests are to ensure that you are *_building the right system_*, while unit tests help ensure that you are *_building the system right_*.
+To put it another way:
 
 [TIP]
 ====
-Isis provides autowiring dependency injection into every domain object.  This is most useful when writing unit tests; simply mock out the service and inject into the domain object.
-====
+Integration tests help ensure that you are *_building the right system_*
 
+Unit tests help ensure that you are *_building the system right_*.
+====
 
 
 
@@ -34,7 +35,7 @@ We further sub-divide integration tests into:
 +
 Even if a domain expert understands the intent of these tests, the actual implementation will be opaque to them.  Also, the only output from the tests is a (hopefully) green CI job
 
-* tests (or rather, specifications) that are implemented in a BDD language such as link:https://cucumber.io/[Cucumber] (we call these _"BDD specs"_) +
+* tests (or rather, specifications) that are implemented in a _behaviour-driven design_ (BDD) language such as link:https://cucumber.io/[Cucumber] (we call these _"BDD specs"_) +
 +
 The natural language specification then maps down onto some glue code that is used to drive the application.  But the benefits of taking a BDD approach include the fact that your domain expert will be able to read the tests/specifications, and that when you run the specs, you also get documentation of the application's behaviour ("living documentation").
 
@@ -61,31 +62,51 @@ What this means is that an Isis application can be tested end-to-end without hav
 
 
 
+== Dependency Injection
 
-== Given/When/Then
+Isis provides autowiring dependency injection into every domain object.  This is most useful when writing unit tests; simply mock out the service and inject into the domain object.
 
-Whatever type of test/spec you are writing, we recommend you follow the given/when/then idiom:
+There are a number of syntaxes supported, but the simplest is to use `@javax.inject.Inject` annotation; for example:
 
-* *given* the system is in this state (preconditions)
-* *when* I poke it with a stick
-* *then* it looks like this (postconditions)
+[source,java]
+----
+@javax.inject.Inject
+CustomerRepository customers;
+----
 
-For unit tests with a mocking library (we tend to use link:http://jmock.org[JMock] but others are also fine) it can be worth considering four steps:
+Isis can inject into this even if the field has package-level (or even `private`) visibility.  We recommend that you use package-level visibility, though, so that your unit tests (in the same package as the class under test) are able to inject mocks.
+
+Isis does also support a couple of other syntaxes:
+
+[source,java]
+----
+public void setCustomerRepository(CustomerRepository customers) { ... }
+----
+
+or
+
+[source,java]
+----
+public void injectCustomerRepository(CustomerRepository customers) { ... }
+----
 
-* *given* the system is in this state
-* *expecting* these interactions (set up the mock expectations here)
-* *when* I poke it with a stick
-* *then* these interactions should have occurred.
 
 [TIP]
-.Distinguish between queries vs mutators
 ====
-For mock interactions that simply retrieve some data, your test should not need to verify that it occurred.  If the system were to be refactored and starts caching some data, you don't really want your tests to start breaking because they are no longer performing a query that once they did.  If using JMock API this means using the `allowing(..)` method to set up the expectation.
-
-On the other hand mocks that mutate the state of the system you probably should assert have occurred.  If using JMock this typically means using the `oneOf(...)` method.
+Apache Isis also supports automatic dependency injection into integration tests; just declare the service dependency in the usual fashion and it will be automatically injected.
 ====
 
 
+
+
+== Given/When/Then
+
+Whatever type of test/spec you are writing, we recommend you follow the given/when/then idiom:
+
+* *given* the system is in this state (preconditions)
+* *when* I poke it with a stick
+* *then* it looks like this (postconditions)
+
 A good test should be 5 to 10 lines long; the test should be there to help you reason about the behaviour of the system.  Certainly if the test becomes more than 20 lines it'll be too difficult to understand.
 
 The "when" part is usually a one-liner, and in the "then" part there will often be only two or three assertions that you want to make that the system has changed as it should.
@@ -103,16 +124,8 @@ In the previous section we discussed using given/when/then as a form of organizi
 
 For integration tests though it can be difficult to keep the "given" short; there could be a lot of prerequisite data that needs to exist before you can actually exercise your system.  Moreover, however we do set up that data, but we also want to do so in a way that is resilient to the system changing over time.
 
-On a very simple system you could probably get away with using SQL to insert directly into the database, or you could use a toolkit such as link:http://dbunit.sourceforge.net/howto.html[dbunit] to upload data from flat files.  Such approaches aren't particularly maintainable though.  If in the future the domain entities (and therefore corresponding database tables) change their structure, then all of those data sets will need updating.
+The solution that Isis provides is a domain service called <<_fixture_scripts, Fixture Scripts>>, that defines a pattern and supporting classes to help ensure that the "data setup" for your tests are reusable and maintainable over time.
 
-Even more significantly, there's no way to guarantee that the data that's being loaded is logically consistent with the business behaviour of the domain objects themselves.  That is, there's nothing to stop your test from putting data into the database that would be invalid if one attempted to add it through the app.
-
-The solution that Isis provides is a small library called *_fixture scripts_*.  A fixture script is basically a wrapper for executing arbitrary work, but that work almost always invoking a business action.  These fixture scripts can then be organized either in a fairly flat structure (eg as in the http://github.com/isisaddons/isis-app-todoapp}[Isis addons' todoapp], or as a composite pattern (eg as in https://github.com/estatio/estatio/blob/ea20a6ce257acede50de6ce4fd2ff29713fcd689/estatioapp/fixture/src/main/java/org/estatio/fixture/invoice/InvoiceForLeaseItemTypeOfDiscountOneQuarterForOxfMiracle005.java#L66)[Estatio open source app].
-
-[TIP]
-====
-If you want to learn more on this topic (with live coding!), check out this https://skillsmatter.com/skillscasts/5638-to-those-whom-much-is-given-much-is-expected[presentation] given at BDD Exchange 2014.
-====
 
 
 
@@ -133,6 +146,20 @@ Using fake data works very well with fixture scripts; the fixture script can inv
 ====
 
 
+
+
+== Feature Toggles
+
+Writing automated tests is just good development practice.  Also good practice is developing on the mainline (master, trunk); so that your continuous integration system really is integrating all code.  Said another way: link:http://martinfowler.com/bliki/FeatureBranch.html[don't use branches]!
+
+Sometimes, though, a feature will take longer to implement than your iteration cycle.  In such a case, how do you use continuous integration to keep everyone working on the mainline without revealing a half-implemented feature on your releases?  One option is to use link:http://martinfowler.com/bliki/FeatureToggle.html[feature toggle]s.
+
+Apache Isis does not, itself, ship with a feature toggle library.  However, the http://github.com/isisaddons/isis-module-togglz}[Isis addons' togglz] module (non-ASF) does provide exactly this capability.
+
+
+
+
+
 With all that said, let's look in detail at the testing features provided by Apache Isis.