Skip to content

Instantly share code, notes, and snippets.

@luuizeduardo
Last active October 21, 2022 15:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save luuizeduardo/48d88925dd9541913f4c5aace81d620c to your computer and use it in GitHub Desktop.
Improve the object mapping
package api.test.java.tests;
import com.fasterxml.jackson.databind.JsonNode;
import io.restassured.response.Response;
import org.example.repositories.FileUtils;
import org.example.services.YourApiService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
@ExtendWith(SpringExtension.class)
@SpringBootTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ApiTest {
private final YourApiService yourApiService;
public ApiTest(YourApiService yourApiService) {
this.yourApiService = yourApiService;
}
@Test
public void testCreateUser() throws IOException {
JsonNode requestBody = FileUtils.readJsonFromFile("user/createUser.json");
Response res = yourApiService.postRequest("/users", requestBody);
assertThat(res.statusCode(), is(equalTo(201)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment