0

我们已经开始使用 citrus 集成框架进行 API 测试。我正在尝试在 oracle 数据库上运行 SQL INSERT 查询。

如果我们运行带有 select 关键字的 SQL,它就可以正常工作,但是如果我们想插入数据,它会抛出空指针 exception.stack trace 下面。可以请一些建议。

com.consol.citrus.exceptions.TestCaseFailedException:测试用例失败

at com.consol.citrus.TestCase.executeAction(TestCase.java:221)
at com.consol.citrus.dsl.runner.DefaultTestRunner.run(DefaultTestRunner.java:189)
at com.consol.citrus.dsl.runner.DefaultTestRunner.query(DefaultTestRunner.java:249)
at com.consol.citrus.dsl.testng.TestNGCitrusTestRunner.query(TestNGCitrusTestRunner.java:170)
at com.consol.citrus.samples.DomainAPITest.sqlPMTest(DomainAPITest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:216)
at com.consol.citrus.dsl.testng.TestNGCitrusTest.invokeTestMethod(TestNGCitrusTest.java:130)
at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:100)
at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:58)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:208)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:635)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

引起:com.consol.citrus.exceptions.CitrusRuntimeException:语句中缺少关键字 SELECT:INSERT INTO CN_RATE_EXHIBIT (ID,RATE_EXHIBIT_CODE,DS,DSL,STATUS,RECIPROCAL_IND,START_DATE,END_DATE,TERM_REASON) 值 (seqCN_RATE_EXHIBIT.nextval,'Citrus_Inte_RE_Code' ,'Citrus_Inte_RE_Code_DS','Citrus_Inte_RE_CodeDSL',null,'Y',to_date('01-JUN-16','DD-MON-RR'),to_date('01-JAN-4000','DD-MON-RR '),'O') 在 com.consol.citrus.actions.ExecuteSQLQueryAction.validateSqlStatement(ExecuteSQLQueryAction.java:266) 在 com.consol.citrus.actions.ExecuteSQLQueryAction.doExecute(ExecuteSQLQueryAction.java:84) 在 com.consol。 citrus.actions.AbstractDatabaseConnectingTestAction.execute(AbstractDatabaseConnectingTestAction.java:62) 在 com.consol.citrus.TestCase.executeAction(TestCase.爪哇:214)

4

2 回答 2

0

堆栈跟踪信息告诉我 Citrus 尝试将您的 INSERT 语句作为 SQL 查询 (SELECT) 处理。当您在一个 SQL 测试操作中混合 INSERT 和 SELECT 语句时,就会发生这种情况。

请将查询语句 (SELECT) 与所有其他语句(如 INSERT、UPDATE、DELETE)分开。只需在测试中使用单独的测试操作即可。此外,当使用 SELECT 以外的语句时,不允许在 SQL 测试操作中使用验证表达式。

Citrus 处理 SELECT 语句的方式与其他语句不同。

于 2016-09-20T07:12:17.263 回答
0

确保您使用的是ExecuteSQLBuilder而不是ExecuteSQLQueryBuilder.

public class ExampleTestDesigner extends TestNGCitrusTestDesigner {

    @Autowired
    private DataSource bookDB;

    @Test
    @CitrusTest
    public void exampleTest() {

        // query uses ExecuteSQLQueryBuilder and should only be used for select statements
        query(bookDB).statement("select ISBN, Name from Books");

        // sql uses ExecuteSQLBuilder and can be used for insert, update, delete, etc, statements
        sql(bookDB).statement("insert into Books (ISBN, Name) values ('1-84149-003-2', 'A Shadow on the Glass')");
}

还要检查文档的数据库操作部分

于 2018-04-25T21:00:03.700 回答