Seiji Sogabe authored on 9 Sep 2015
RuleSet RuleSet & FindBugs Checkstyle check 2 years ago
src removed tests of objects() 2 years ago
.gitignore ログまわりの修正 2 years ago
README.md Fixed #6 supported pathParameter 2 years ago
pom.xml updated to 0.3 2 years ago
README.md

Mocking

Build Status

Mocking is a test framework which is inspired by Restito.

Mocking provides a DSL to:

  • Mimic rest server behavior
  • Record HTTP calls to the server
  • Perform verification against happened calls
  • Automatic serialization

Quick example

public class SampleCodeTest {

    private static final int PORT = 8888;

    @Rule
    public Mocking mocking = new Mocking();

    @Rule
    public TestNameRule testNameRule = new TestNameRule();

    @Before
    public void setUp() throws Exception {
        mocking.port(PORT).logging(true);
        RestAssured.port = PORT;
    }

    @Test
    public void testReadMeSampleCode() {
        Person person = new Person("Bob", 20);

        // Mocking
        mocking.$(
                when("/api/p/{id}").
                        withPathParam("id", 5).
                then().
                        withStatusCode(SC_201_CREATED).
                        withContentType("application/json; charset=UTF-8").
                        withBody(person)
        );

        // Rest-assured
        given().
                pathParam("id", 5).
                accept("application/json").
                contentType("application/json; charset=UTF-8").
                body(person).
        when().
                put("/api/p/{id}").
        then().
                statusCode(SC_201_CREATED).
                contentType("application/json; charset=UTF-8").
                body("name", is("Bob")).
                body("old", is(20));

        // Mocking
        mocking.$(
                put("/api/p/{id}").
                        withPathParam("id", 5).
                then().
                        withAccept("application/json").
                        withContentType("application/json; charset=UTF-8").
                        withBody("name", is("Bob")).
                        withBody("old", is(20))
        );
    }
    
(snip)
    
}