如何使用依赖注入空手道(Picocontainer)

时间:2018-03-07 07:58:21

标签: cucumber karate

我有一个项目,我使用黄瓜,放心,硒和Appium,我试图将API测试移动到空手道,并且无法在pom.xml中使用它和picocontainer依赖。

    org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException: com.intuit.karate.ScriptEnv has unsatisfied dependency 'interface com.intuit.karate.cucumber.KarateReporter' for constructor 'public com.intuit.karate.ScriptEnv(java.lang.String,java.io.File,java.lang.String,java.lang.ClassLoader,com.intuit.karate.cucumber.KarateReporter)' from org.picocontainer.DefaultPicoContainer@66ac5762:11<|
at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:191)
  at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:110)
  at org.picocontainer.injectors.ConstructorInjector.access$100(ConstructorInjector.java:51)
  at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:331)
  at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
  at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
  at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
  at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
  at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
  at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
  at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
  at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
  at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
  at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
  at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
  at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
  at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
  at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
  at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
  at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
  at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
  at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
  at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
  at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
  at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
  at cucumber.runtime.java.picocontainer.PicoFactory.getInstance(PicoFactory.java:40)
  at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
  at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
  at cucumber.runtime.Runtime.runStep(Runtime.java:300)
  at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
  at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
  at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
  at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
  at cucumber.runtime.Runtime.run(Runtime.java:122)
  at cucumber.api.cli.Main.run(Main.java:36)
  at cucumber.api.cli.Main.main(Main.java:18)
  

如何使用依赖注入添加空手道设置   PicoContainer的。

1 个答案:

答案 0 :(得分:0)

空手道不支持Cucumber DI,实际上并不需要它。

因为您可以非常轻松地调用Java代码并在需要时重复使用:https://github.com/intuit/karate#calling-java

但我们鼓励你尽可能地在空手道和JS中做所有事情,这样你才能获得最大的收益。