Creating a test project with Maven - wmaop/wm-jbehave GitHub Wiki
Maven gives an easy way to manage package/project dependencies and provide a consistent way for developers to automatically set up projects within Eclipse. The method below shows the steps to manually create a Maven project definition file which is a one-off task per IS package. Once created, the package can be imported into Designer and all configuration and dependencies will set up without further interaction.
Running JBehave tests results in the execution of a java class, finding the tests within a directory then exercising these tests against a running IS (Local by default but can be a server elsewhere). There is no explicit need for the tests to be located within the IS package which they are being tested. A test project therefore can be a stand alone Java project that only runs tests or the tests can be included into the IS package and the package Maven enabled.
- From within the Java Perspective in Designer, File -> New -> Maven Project (If this is not visible, choose File -> New -> Other... -> Maven -> Maven Project)
- To set up as an independent project, ie not related to an IS package:
- Choose a location where the project resides and from which you can commit the project into source control. Then click Next
- Alternatively, to set up IS package as a Maven project to include tests:
- Choose the location where the IS package resides. If you're running a local IS instance, navigate to the location of the package or if using a remote server, a mount/mapped drive to the directory.
- Choose the maven-archetype-quickstart and click Next
- Enter a group id related to your company domain and team, eg: com.acme.inttech
- Add an artifact id related to the IS package, eg: ComAcmeBilling
- Set the version to 1.0.0-SNAPSHOT
- Click Finish. This will create the project and should show the project folder icon with a 'm' in the top left.
With the project created, the next steps set up the library dependencies so that the correct version of JUnit is used and the wm-jbehave runtime is import for running the tests:
- In the Navigator or Package Explorer view, locate the pom.xml file, open it and select the dependencies tab
- If the version of JUnit is showing as 3.8.1, ie, pre 4.0, click the junit line, click Properties... and change the version to 4.12 then click OK.
- To add the JBehave runtime to the project, click Add... for the Dependencies and enter
- If you click the pom.xml tab there should be the definition with the wm-jbehave and junit dependencies showing:
<dependencies>
<dependency>
<groupId>org.wmaop</groupId>
<artifactId>wm-jbehave</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
If errors exist in the project, open the pom.xml file to check if the wm-jbehave dependency is not found. Verify that your Designer has access to the internet in order to retrieve the jar dependencies. You can refresh the project if you correct the problem and its still not apparently working by right clicking on the project and selecting Maven -> Update Project... then clicking OK
With the project and dependencies fully defined, next the directories and static configuration needs creating. This could be from an unzipping of a template, a Maven archetype or other means to create default directory and files. Within the Navigator view:
- Create a src/test/resources/data folder into which all your IData XML files should reside
- Create a src/test/resources/stories folder where all you .story files should be created
- Add a log4j.properties file into src/test/resources with default output:
# Root logger option
log4j.rootLogger=INFO, stdout
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
- Create a Java class in src/test/java/test. Call it TestRunner.java and put in the following content. This is the file you will right-click and Run As JUnit Test when you want to execute tests.
package test;
import org.junit.runner.RunWith;
import org.wmaop.bdd.jbehave.JBehaveRunner;
import de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner;
@RunWith(JUnitReportingRunner.class)
public class TestRunner extends JBehaveRunner {}
All the configuration at this point is complete. Next is a simple test to prove the project is set up and the configuration in your IS server is set up correctly.
- Create your first story. Right click on src/test/resources/stories and select New -> Other then choose JBehave Story (Or type 'story' at the top)
- Click Next > and give it a name, eg HelloWorld
- Paste in a sample to your story to test it:
Verify pipeline interaction
Narrative:
In order to observe service state
As a test framework
I want to interact with the pipeline
Scenario: Verify setting of pipeline values
Given pipeline values inString1 = "hello "; inString2 = "world"
When invoke pub.string:concat without idata
Then show pipeline in console
Then pipeline has value == "hello world"
- Run the test by right-clicking on the TestRunner class and selecting Run As JUnit Test Your story should run and show a green bar within the JUnit view. You can also right-click on the project and run as JUnit.
You may see the following error when first running:
Unable to connect to localhost:5555 with Administrator/manage - Connection refused: connect
If your IS instance is not running as localhost:5555 with the usual Administrator/manage then you'll need to change the run configuration to pass in the server location.
- Right-click on the TestRunner class (Or the project if you're running from there) and select Run As -> Run configurations...
- If you haven't run the project/class before there's none shown so you can either:
- right click JUnit and select 'new' and ensure its set to JUnit4
- or cancel, right click the project/class and select Run As JUnit which will of course fail but correctly set up the profile. Just right click on the project/class and select Run As -> Run configurations...
- Click the Arguments tab
- In the VM arguments section you can add parameters to configure the location, one argument per line. The values are:
- -Dwm.server.host=XXX where XXX is the host name or IP address, default is localhost
- -Dwm.server.port=PPP where PPP is the server port, default is 5555
- -Dwm.server.username=UUU where UUU is the user to connect to IS, default is Administrator
- -Dwm.server.password=PPP where PPP is the password, default is manage
- Click Apply and Run to execute the test and verify your connection details