Running manual Cucumber tests in Java

How to run manual Cucumber tests in Java

In theory, it would be nice to have everything automated. In reality, it might be the case that for some reasons you have to run and manually verify test results.

There can be a number of ways for running manual Cucumber tests, for Ruby there’s even whole CukeHub to run and organize manual tests, but my research yielded no results on how to do manual testing in Java.

So, let’s implement it our self.

Used example

I picked some simple demo for ATM. It had some outdated dependencies, but could serve as a good starting point.

Defining feature

Let’s take one of scenarios in feature file and add the desired functionality

    Scenario: Manual test 1
        Given I have 50 SEK on my account
        When I withdraw -1 SEK
        Then I get 0 SEK from the ATM
        And error message about incorrect amount is displayed
        And evaluate manually

Step we want is the last one. Cucumber should run its tests, evaluate some of the results and then await for users’ final decision. Since we want to exclude manual tests from automated runs, we should also annotate those scenarios somehow. I went with ‘@manual’ tag.

Now to define this step

    @Then("^evaluate manually$")
    public void evaluate_manually() throws Throwable {
        System.out.println("Mark feature as [p]assed or [f]ailed?");
        Scanner sc = new Scanner(;
        String s = sc.nextLine();
        while (!s.equals("f") && !s.equals("p")) {
            System.out.println("Unknown input: " + s);
            s = sc.nextLine();
        assertThat("User marked test as failed", s, is("p"));

Keep asking user to provide his assessment until he finally gives up and gives us what we want — either “p” or “f”. Then throw an exception if input isn’t “p”. With such simple code nothing can go wrong, right?


Problem with Maven

If you run your Cucumber tests with ‘mvn clean test’ (the way every Cucumber tutorial suggests) then you get but one problem. Maven blocks System input, preventing our Scanner from giving us any input – no matter how hard user smashes his “enter” key, our app just won’t receive a single line of input and will stay soft locked.

To work around this problem and get an easy-to-use solution we need 2 components. One is ’exec-maven-plugin’, which allows us to execute custom java code bypassing mvn test restrictions, and second is cucumber.api.cli.Main usage info. All we need to do is add exec-maven-plugin, specify ‘mainClass’ as ‘cucumber.api.cli.Main’, define ‘classpathScope’ as ’test’ and provide in arguments path to our feature and glue code files, and Cucumber plugins.


                <!-- Uncomment the following line if you want to run manual tests with mvn test command -->
                <!-- Specify the location of .feature files -->
                <!-- Specify the location of gluecode classes - in our case that's WithdrawSteps -->
                <!-- Define plugins - first one ensures that console output is colorful,
                    second one gives location for report file -->
                <!-- Cucumber Tag expression.  -->

I find it best to annotate Runner class to prevent manual tests from being executed with automated:

@CucumberOptions(plugin = {"pretty", "json:target/cucumber/cucumber.json"},
        tags = {"not @manual"})
public class RunCukesTest {


Now we can run automated tests with mvn test and manual with mvn test-compile exec:java. With current configuration it will provide 2 json report files which can be merged in several ways, depending on how you store your results.

If you prefer to have results in html format, you can merge reports by copying one report.js file starting from second line and excluding last into penultimate line of another report.js.


Complete example for this post can be found here.