空手道专家您好,
我在尝试从 IntelliJ 执行空手道测试时看到以下错误。
*<ServiceName>*.ParallelRunner > testParallel FAILED
java.lang.ExceptionInInitializerError
at com.intuit.karate.Runner$Builder.tagSelector(Runner.java:80)
at com.intuit.karate.Runner.parallel(Runner.java:309)
at com.intuit.karate.Runner$Builder.parallel(Runner.java:190)
at com.intuit.karate.Runner.parallel(Runner.java:218)
at com.intuit.karate.Runner.parallel(Runner.java:214)
at *<ServiceName>*.ParallelRunner.testParallel(ParallelRunner.java:30)
Caused by:
java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.createBindings()" because "com.intuit.karate.ScriptBindings.NASHORN" is null
at com.intuit.karate.ScriptBindings.createBindings(ScriptBindings.java:160)
at com.intuit.karate.core.Tags.<init>(Tags.java:158)
at com.intuit.karate.core.Tags.<clinit>(Tags.java:48)
... 6 more
1 test completed, 1 failed
Finished generating test XML results (0.006 secs) into: /Users/*<empId>*/*<ServiceName>*/build/test-results/acceptanceTests
Generating HTML test report...
Finished generating test html results (0.005 secs) into: /Users/*<empId>*/*<ServiceName>*/build/reports/tests/acceptanceTests
> Task :acceptanceTests FAILED
FAILURE: Build failed with an exception.
我使用的空手道版本是 testImplementation 'com.intuit.karate:karate-junit4:0.9.6' 和 java 版本是 17。有人可以建议解决此错误的最佳方法吗?
以下命令通过了必要的凭据,用于执行测试
./gradlew clean acceptanceTest -Dkarate.clientId='<>' \ ─╯
-Dkarate.clientSecret='<>' \
-Dkarate.abTestMgmt='<>' \
-Dkarate.env='<>' -Dkarate.options="--tags @CRUD_ConfigurationId" --info
下面是paralleRunner文件
package *<serviceName>*;
import com.intuit.karate.KarateOptions;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import lombok.extern.slf4j.Slf4j;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static junit.framework.TestCase.assertTrue;
@Slf4j
@KarateOptions(tags = {"~@newFeature", "~@ignore", "~@50Test"})
public class ParallelRunner {
@Test
public void testParallel() {
Results results = Runner.parallel(getClass(), 10);
generateReport(results.getReportDir());
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[]{"json"}, true);
List<String> jsonPaths = new ArrayList<>(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "*ServiceName*_AcceptanceTest");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
空手道版本的升级可能会有所帮助,但该项目使用 junit4 进行集成和单元测试。继续前进最好的事情是什么?
我尝试将空手道版本升级到最新版本,但由于使用了 junit 依赖项,在集成和单元测试中看到了很多错误。谢谢!!
删除 karate-apache 依赖项。所以你只剩下
karate-junit5 依赖于最新版本。这对我有用。