java - RestAssured:java.lang.IllegalArgumentException:要使用的架构不能为空?
问题描述
我需要将我的 api 测试响应与外部 JSON 文件进行比较。
执行我的 api 测试时,似乎看到以下异常:'java.lang.IllegalArgumentException: Schema to use cannot be null'。
我的测试:
@Test
public void validateAgainstJsonFile() {
given()
.spec(footballCompetitions_requestSpecification)
.when().get(EndPoint.AREAS + "2014")
.then()
.assertThat()
.body(matchesJsonSchemaInClasspath("footballCompetitions.json"));
}
我的项目结构如下所示:
堆栈跟踪:
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)
解决方案
test
尝试在调用下创建一个文件夹resources
并将文件移到那里,footballCompetitions.json
例如:/test/resources/footballCompetitions.json
test
└─── java
└─── resources
└─── footballCompetitions.json
然后.body(matchesJsonSchemaInClasspath("footballCompetitions.json"));
应该可以正常工作。
推荐阅读
- java - org.apache.pdfbox.pdfparser.NonSequentialPDFParser checkXrefOffsets 严重:找不到对象 8 0(原点偏移量 0)
- git - 运行 Jenkins 管道,但在管道运行之前修改代码
- html - CSS 在悬停时更改链接颜色
- javascript - 语法错误:预期的表达式,在 php 和 javascript 中得到 '}'
- android - 为什么文本小部件带有下划线?
- c# - 这段代码是如何工作的?这里类名在其自己的实现中用作数据类型
- scala - 将rdd保存到镶木地板文件scala
- swift - collectionView 单元格中的收藏按钮
- java - 如何在 Junit 中生成可读的真值表测试数据
- assembly - 将 GAS 转换为 MASM 时我做错了什么?