Wednesday, 18 September 2013

Adding cucumber-jvm to projects

Add these 2 dependencies in the pom.xml



In the Test add a acceptance folder

Then Add the following class

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@Cucumber.Options(format = {"pretty", "html:target/cucumber-html-report", "json-pretty:target/cucumber-json-report.json"}, tags = "~@wip")
public class RunCukesTest {

Now when you run 

>mvn test

It will complain that there are no feature file

Now in the resources folder based on your package structure create acceptance folder and then add a sample feature

Feature: Testing for sample core

Scenario Outline: Successful login

        Given I want to use the browser [browser]
        When I type testuser1 in the username input field
        When I type testuser1 in the password input field
        And I click the login button
        Then I am on the launcher page

                |     browser            |
                |     Firefox            |
                |     Chrome             |
                |     InternetExplorer   |

Now when you run >mvn test

it will ask us to implement the feature

You can implement missing steps with the snippets below:

@Given("^I want to use the browser \\[browser\\]$")
public void I_want_to_use_the_browser_browser() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();

@When("^I type testuser(\\d+) in the username input field$")
public void I_type_testuser_in_the_username_input_field(int arg1) throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();

you have configured cucumber-jvm to your projects

Adding Apache log4j

in pom.xml add the log4j dependency



in resources add a new file

# Root logger option
log4j.rootLogger=debug, stdout

# Direct log messages to stdout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

Now you should be able to log in messages

For mockito add this dependency



We can have exception rules as


    public ExpectedException expectedEx = ExpectedException.none();

    public void shouldAcceptOnlyIncrementOf100Messages() {
        expectedEx.expectMessage("The number of messages per seconds must be multiple of 100 )");
        new FixedRateMessageInjector(queueDriver, 108, 2);

In case if you want to use AWS add