RestAssured: java.lang.IllegalArgumentException: используемая схема не может быть нулевой? - PullRequest
0 голосов
/ 08 января 2019

Мне нужно сравнить ответ теста API с внешним файлом JSON.

Кажется, что я вижу следующее исключение: 'java.lang.IllegalArgumentException: используемая схема не может быть нулевой' при выполнении моего теста API.

Мой тест:

@Test
public void validateAgainstJsonFile() {
    given()
            .spec(footballCompetitions_requestSpecification)
            .when().get(EndPoint.AREAS + "2014")
            .then()
            .assertThat()
            .body(matchesJsonSchemaInClasspath("footballCompetitions.json"));
}

Структура моих проектов выглядит следующим образом:

https://ibb.co/M62rHyF

Трассировка стека:

java.lang.IllegalArgumentException: Schema to use cannot be null

    at io.restassured.module.jsv.JsonSchemaValidator.validateSchemaIsNotNull(JsonSchemaValidator.java:270)
    at io.restassured.module.jsv.JsonSchemaValidator.access$300(JsonSchemaValidator.java:75)
    at io.restassured.module.jsv.JsonSchemaValidator$JsonSchemaValidatorFactory.create(JsonSchemaValidator.java:281)
    at io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchema(JsonSchemaValidator.java:166)
    at io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath(JsonSchemaValidator.java:117)
    at apiTests.footballData.CompetitionsGetTest.validateAgainstJsonFile(CompetitionsGetTest.java:195)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

Ответы [ 2 ]

0 голосов
/ 08 января 2019

Попробуйте создать папку под test с именем resources и переместить туда файл footballCompetitions.json что-то вроде: / test / resources / footballCompetitions.json

 ? test
    └─── ? java
    └─── ? resources
         └─── footballCompetitions.json

Тогда .body(matchesJsonSchemaInClasspath("footballCompetitions.json")); должно работать нормально.

0 голосов
/ 08 января 2019

Вы уверены, что путь к файлу правильный? Переместите этот файл в: /test/resources/

или используйте абсолютный путь, как показано ниже: .body(matchesJsonSchemaInClasspath("/src/test/java/apitests/footballData/footballCompetitions.json"));

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...