使用外部库Spring Framework通过模拟执行Karate jar [英] Executing Karate jar with mock using external library Spring Framework
问题描述
早上好.我正在使用空手道独立版的项目中工作.我是空手道的新手,请原谅我缺乏知识.
Good morning. I am working on a project that uses Karate Standalone. I am completely new to Karate to excuse my lack of knowledge here.
使用" -m "命令行参数执行独立的空手道罐,以启动模拟功能. mock.feature引用了一个基于' org.springframework.amqp '构建的utils类.
The standalone karate jar is executed with the '-m' command line parameter to start a mock.feature. The mock.feature references a utils class that is built on 'org.springframework.amqp'.
问题是由于外部库' org/springframework/amqp/rabbit/connection/ConnectionFactory '
api1_mock_test.feature
Feature: API1 Mock Test
Background:
* def RabbitUtils = Java.type('utils.RabbitUtils')
.
.
我们的RabbitUtils只是一个Java类,它导入org.springframework.amqp外部库以提供与Rabbit AMQP代理进行交互的功能,例如连接,接收,发布,清除等.在IntelliJ中构建和运行时,一切正常.该项目中的POM参考是:
Our RabbitUtils is just a java class that imports org.springframework.amqp external libraries to provide functions to interact with a Rabbit AMQP broker e.g. connect, receive, publish, purge etc. When built and run in IntelliJ all works ok. The POM reference in the project is:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
空手道独立jar是否有某种引用外部库的方法?设置classpath参数以引用我们的工作空间".\ target \ test-classes ",并且包含RabbitUtils.class文件.
Does the Karate standalone jar have some way of referencing external libraries? The classpath parameter is set to reference our workspace '.\target\test-classes' and contains the RabbitUtils.class file.
从工作空间根目录执行的当前执行如下:
The current execution from workspace root looks like this:
java -jar C:\intuit\karate-0.9.3.RC2.jar -cp .\target\test-classes -p 6868 -m .\src\test\java\mocks\api1_mock_test.feature
08:57:05.122 [main] INFO com.intuit.karate.Main - Karate version: 0.9.3.RC2
08:57:05.891 [main] ERROR com.intuit.karate - server-side background init failed - api1_mock_test.feature:4
Exception in thread "main" picocli.CommandLine$ExecutionException:
-unknown-:4 - org/springframework/amqp/rabbit/connection/ConnectionFactory
谢谢!
推荐答案
感谢您提出这个问题,我想我已经找到了一种实现此目标的方法,这带来了很多可能性.解决方案是使用Java第一性原理,而不使用-jar
选项.空手道命令行应用程序(或CLI)类恰巧是com.intuit.karate.Main
.我将在此处提供使用 SikuliX 的演示.首先,功能文件test.feature
:
Thanks for asking this, and I think I've figured out a way to do this which opens up a lot of great possibilities. The solution is to use Java first-principles, and not use the -jar
option. The Karate command-line-app (or CLI) class happens to be com.intuit.karate.Main
. I'm going to provide a demo here of using SikuliX. First, the feature file test.feature
:
Feature: sikuli test
Background:
* def Screen = Java.type('org.sikuli.script.Screen')
Scenario:
* def s = new Screen()
* def c = s.capture()
* c.getFile('.')
并将karate.jar
和sikulixapi.jar
放在命令行的同一文件夹中,此方法有效(对于Windows,请使用;
而不是:
作为路径分隔符"):
And with the karate.jar
and sikulixapi.jar
in the same folder on the command line, this works (for windows, use ;
instead of :
as the "path separator"):
java -cp karate.jar:sikulixapi.jar com.intuit.karate.Main test.feature
这篇关于使用外部库Spring Framework通过模拟执行Karate jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!