mardi 5 février 2019

Tests with multi-line string are marked as passed when run separately (java+maven+cucumber)

I have tests on java + maven + cucumber. Test creates a request to a remote API (https://jsonplaceholder.typicode.com/) and checks that the answer received in json is correct.

Cucumber scenario:

Scenario Outline: Check a post body
  When user requests for the post by it's <id> as id
  Then response code is 200
  And response for the post returns correct body <body>

Examples:
|id |body|
|1  |quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto|
|18 |eveniet quo quis\nlaborum totam consequatur non dolor\nut et est repudiandae\nest voluptatem vel debitis et magnam|
... etc...

Json responce is parsed by ObjectMapper and stored in java class:

package responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Posts {

public Posts(){};

private int userId;
private int id;
private String title;
private String body;

public int getUserId() {return userId;}

public void setUserId(int userId) {this.userId = userId;}

public int getId() {return id;}

public void setId(int id) {this.id = id;}

public String getTitle() {return title;}

public void setTitle(String title) {this.title = title;}

public String getBody() {return body;}

public void setBody (String body) {this.body = body;}}

.

BufferedReader br = new BufferedReader(new 
InputStreamReader(connection.getInputStream()));
    ObjectMapper mapper = new ObjectMapper();
    Posts post = mapper.readValue(br, Posts.class);

And then both strings are compared:

@Then("^response for the post returns correct body (.*)")
  public void response_for_the_post_returns_correct_body(String body) throws IOException {
  Assert.assertEquals(body, RequestSender.get_data_from_post("body", connection));
}  

With the settings like above, when I run a single scenario, it is marked as 'passed' in Idea. But when I run all tests with maven 'mvn test', tests fail.

But if I change 'body string' to something completely different like '12345', it fails when I run single scenario as well.

The problem is only with this 'Body' parameter (I guess, because it contains a multi-string value)

Why does it happen? How I can fix this?

Aucun commentaire:

Enregistrer un commentaire