我正在爲Cucumber編寫Scala代碼的測試。我有以下的步驟從字符串到BigDecimal的轉換不要在Scala上使用黃瓜
When added product with price 10.0
而以下步驟定義:
When("""^added product with price ([\d\.]*)$""") {
(price: BigDecimal) => {
//something
}
}
當我的IntelliJ運行測試,我得到以下錯誤:
cucumber.runtime.CucumberException: Don't know how to convert "10.0" into scala.math.BigDecimal.
Try writing your own converter:
@cucumber.deps.com.thoughtworks.xstream.annotations.XStreamConverter(BigDecimalConverter.class)
public class BigDecimal {}
at cucumber.runtime.ParameterInfo.convert(ParameterInfo.java:104)
at cucumber.runtime.StepDefinitionMatch.transformedArgs(StepDefinitionMatch.java:70)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:38)
at cucumber.runtime.Runtime.runStep(Runtime.java:289)
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:40)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:116)
at cucumber.runtime.Runtime.run(Runtime.java:120)
at cucumber.runtime.Runtime.run(Runtime.java:108)
at cucumber.api.cli.Main.run(Main.java:26)
at cucumber.api.cli.Main.main(Main.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
我試圖實現自己的變壓器,但我不能adnotate scala.math.BigDecimal
class BigDecimalConverter extends Transformer[BigDecimal] {
override def transform(p1: String): BigDecimal = BigDecimal(p1)
}
你有什麼建議爲什麼Cucumber沒有加載cucumber.runtime.xstream.BigDecimalConverter?