Open BobCAE opened 2 years ago
Ok, let's model a test case. Are you familiar with REST API testing?
no
Ok. Please enter a name for the test case:
Create dish rating test
Test case will be named "Create dish rating test". Please enter the request method (e.g., GET, POST,...):
post
Please enter the request path (e.g., /mensa/Aachen/dishes):
/dishes/1/ratings
The test request will be POST
/dishes/1/ratings
. Do you want to include a JSON body to the request?
yes
Ok, please enter the request body:
{ "stars": 5, "comment": "Very delicious!" }
Request body was set. Do you want to include assertions on the response to this request?
yes
Ok. Which type of assertion should be added? Please enter a number:
1
Which response status code do you expect?
201
Added assertion to the test. Here is an overview of the current assertions:
Do you want to add another assertion?
no
Ok. Here is the generated test method code:
public void testCreatedishratingtest() {
MiniClient c = new MiniClient(mainPath);
c.setConnectorEndpoint(connector.getHttpEndpoint());
try {
c.setLogin(AnonymousAgentImpl.IDENTIFIER, "");
ClientResponse result = c.sendRequest("POST", "/dishes/1/ratings", """
{
"stars": 5,
"comment": "Very delicious!"
}""", "application/json", "*/*", new HashMap<>(), new Object[0]);
Assert.assertEquals(201, result.getHttpCode());
} catch (Exception e) {
e.printStackTrace();
fail("Exception: " + e);
}
}
I want to model a test.