English 中文(简体)
使用空手道为包含 DAO 的 API 建立元件测试?
原标题:Using Karate to build a component test for an API that contains a DAO?

我学着用空手道为以爪哇为基地的API开发自动化测试,该API包含一个DAO层,可以与数据库交谈,检索一些信息并反馈给受访者。这是简单化的工作流程 :

GET payments-information -> Calls PaymentsInformationService -> Calls a PaymentInformationDAO -> Calls a MYSQL Database -> Returns 200OK

有(假)代码 :

PaymentInformationServiceImple -> PaymentsInformationDAOImple.getPayments(int custId)

我来自一些背景,在NodeJS(我在这里使用笑语,用一个简单的参考函数将支付服务的依赖性分解为上面的dao)进行组件测试。 我试图在Karate和Java Impl 类中也这样做,我需要在那里实时把 PaymentInformationDAO 拆掉,这样组件测试就不会变成一个实时集成测试(因为我不想测试对数据bae的实际呼叫,而是在做/GET呼叫服务时将这些电话单独粘住)

我一直在寻找信息,比如用铁丝网堵住下游API的电话。就我而言,我需要切断DAO本身不是API电话的DAO。我该怎么处理这个?

问题回答

空手道在 HTTP 层工作, 因此服务的内部细节通常超出了范围 。 但是由于空手道在幕后是一个爪哇lib, 它与爪哇和例如春天项目之间运作良好。 但是如何设置后端来使用模拟而不是实际执行的问题不属于空手道的范围 。

因此,我建议你与后端团队合作使用你的模拟方法。 如果这是一个 Spring 工程, 它应该相当微不足道, 比如在命令线上通过一些 env 的标志。 如果您需要 Spring 具体的例子, 您可以找到一个 < a href=" https:// github.com/karatelabs/karate-examples/blob/main/ database/README. md" rel= “ nofolvererr'> 。 有关模拟依赖性的信息可以找到 < a href=> https://stackoverflow.com/a/61414022/14475>>here 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签