Skip to content

leanovate/cucumber-rest-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Helper classes to test REST service using cucumber-jvm

This is only supposed to work with: Cucumber JVM

The main party trick is that all HTTP requests are recorded and added to the cucumber report so that it is obvious what is happening.

Usage

Take a look in /examples or Book DB example for a full setup.

pom.xml

<dependency>
    <groupId>de.leanovate.cucumber</groupId>
    <artifactId>rest-helper</artifactId>
    <version>0.9</version>
    <scope>test</scope>
</dependency>

Ensure that you include classpath:de/leanovate/cucumber in your glue path. Like this:

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:target/cucumber"}, tags = {"~@ignore"},
        glue = {"classpath:your/glue/package", "classpath:de/leanovate/cucumber"})
public class RunCukesTest {
}

Now you can inject the TestHttpClient into your stepdefs:

import de.leanovate.cucumber.rest.TestHttpClient;
import org.apache.http.client.fluent.Request;

import static de.leanovate.cucumber.rest.RestAssertions.assertThat;

public class MyStepdefs {
    private final TestHttpClient client;
    
    public MyStepdefs(TestHttpClient client) {
    	  this.client = client;
    }
    
    @When("^Get the thing$")
    public void get_the_thing() throws Throwable {
        Request request = Request.Get("http://localhost/thing");
    		
        HttpResponse response = client.execute(request);
        
        assertThat(response).isOk();
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages