Testing a Rapidoid rest api

10th of March, 2020

In this post i will try to explain how to write an integration test for rest apis written using Rapidoid.

To test your rest api, there are two things need to do:

  1. extend your test class with RapidoidIntegrationTest
  2. Annotate your test class with @IntegrationTest, and pass the main class parameter.

Something like below:

@IntegrationTest(main = Main.class)
public class UserIntegrationTest extends RapidoidIntegrationTest {
}

For writing the test case, it is simple:

  • Use Self class for performing all the rest calls.

like below:

    @Test
    public void shouldInsertUser() {
        Map<String, ?> user1 = U.map("name", "Kuldeep");
        User user = Self.post("/users").data(user1).toBean(User.class);
        Assert.assertThat(user.getId(), Is.is(1L));
    }

In addition to the assertion api provided by Junit, RapidoidTest provides some sugarcoated methods for assertion.