skyscreamer / JSONassert

Write JSON unit tests in less code. Great for testing REST interfaces.
http://jsonassert.skyscreamer.org
Apache License 2.0
1k stars 197 forks source link

JSONCompare.compareJSON should fail on crashed json #103

Open Kamil-Benedykcinski opened 6 years ago

Kamil-Benedykcinski commented 6 years ago

Snippet below fails:(

import org.junit.Test;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONCompare.compareJSON;

public class JsonAssertTest {

    @Test
    public void shouldFailOnCrashedJson() {
        // given
        String validJson = "{\"id\":\"abc\"}";
        String crashedJson = "{\"id\":abc}";

        // when
        JSONCompareResult jsonCompareResult = compareJSON(validJson, crashedJson, JSONCompareMode.STRICT);

        // then
        assertThat(jsonCompareResult.failed()).isTrue();
    }
}
shiye1999 commented 3 years ago

The json auto add " to the json string. If i use another lib of json like fastjson,the compare would fail.