A framework for building behaviour-driven tests in fluent Java. Copyright 2010 youDevise, Ltd..
Download the Narrative jar file and the Hamcrest Matchers library (version 1.2). Then, put both in your classpath where your test code can see it.
Here is a typical Narrative test (the object under test is a very simple calculator):
@Test public void
adds_two_numbers() {
Given.the( operator).was_able_to( press('2'))
.was_able_to( press('+'))
.was_able_to( press('2'));
When.the( operator).attempts_to( press('='));
Then.the( operator).expects_that( the_displayed_value(), is("4"));
}
To make this test work, you need to define:
operator, anActorwhich manipulates the calculatorpress()andthe_displayed_value(), which tell theoperatorto perform actions on the calculator
You can see these implementations in our most basic example. We plan to add more examples in the examples directory of the source code.
We build using Gradle. But you don't need Gradle installed to build Narrative.
In the Narrative home directory, type ./gradlew (on Linux and Mac) or gradlew.bat (on Windows). This will build, run tests, and put Narrative.jar in build/libs.
Use gradle to build, run tests, and produce the Narrative.jar in build/libs.
To view Narrative source code in Eclipse:
- Run
gradle :eclipse(or./gradlew :eclipse). This downloads the libraries and creates the project and classpath files. - Create a new classpath variable in Preferences / Java / Build Path / Classpath Variables with the name
GRADLE_CACHEand the value<USER_HOME>/.gradle/cache(we have not tested this on Windows). - Import the project as normal.
Open source under the very permissive MIT license.
A project of youDevise. We're hiring!
Inspired by JNarrate, a RiverGlide idea.