我的要求是運行黃瓜測試用例使用Spring啓動運行一個自定義java主類。 我能夠運行黃瓜測試套件的罰款,如果我使用下面的配置類: -跑步黃瓜和春季開機主類
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {
"html:target/cucumber-html-report",
"json:target/cucumber.json", "pretty:target/cucumber-
pretty.txt",
"usage:target/cucumber-usage.json", "junit:target/cucumber-
results.xml" },
features = { "src/test/resources" },
tags = {"@passed"},
glue = "cucumberTest.steps")
public class RunGwMLCompareTests {
}
而且下面的類加載
@RunWith(SpringRunner.class)
@ActiveProfiles("dev")
@SpringBootTest(classes = Application.class)
public class AbstractDefinitions {
public AbstractDefinitions() {
}
}
當我運行RunGwMLCompareTests類,現在用這個配置我的黃瓜測試用例正在運行,它加載了我的Spring啓動上下文,然後優於功能中定義的所有情況。
現在我的問題是,我想從單獨的主要Java類運行此。我創建了我的java類,如下所示: -
package cucumberTest;
import cucumber.runtime.ClassFinder;
import cucumber.runtime.RuntimeOptions;
import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.io.ResourceLoaderClassFinder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class CucumberMainTest {
public static void main(String[] args) throws IOException {
ClassLoader classLoader = CucumberMainTest.class.getClassLoader();
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new
ResourceLoaderClassFinder(resourceLoader, classLoader);
List<String> pluginList = new ArrayList<>();
pluginList.add("--plugin");
pluginList.add("html:target/cucumber-html-report");
pluginList.add("--plugin");
pluginList.add("json:target/cucumber.json");
RuntimeOptions ro = new RuntimeOptions(pluginList);
ro.getFilters().add("@passed");
ro.getFeaturePaths().add("src/test/resources");
ro.getGlue().add("cucumberTest/steps");
cucumber.runtime.Runtime runtime = new
cucumber.runtime.Runtime(resourceLoader, classFinder, classLoader,
ro);
runtime.run();
}
}
它執行我的測試用例,但不加載我SpringContext,結果無春豆loadedand我得到空指針異常..任何幫助geatly讚賞。
問候, 維克拉姆Pathania