Cucumber-jvm线程安全吗?

fhc*_*cat 7 java multithreading gradle gpars cucumber-jvm

我想在多个线程中运行相同的Cucumber测试.更具体地说,我有一组功能,在一个线程中运行这些功能可以正常工作.我使用JSON格式化程序来记录每个步骤的运行时间.现在我想做负载测试.我更关心多线程环境中每个功能/步骤的运行时间.所以我创建了多个线程,每个线程都运行在同一个功能集上.每个线程都有自己的JSON报告.理论上这可能吗?

对于某些项目设置原因,我无法使用JUnit运行程序.所以我不得不采用CLI方式:

        long threadId = Thread.currentThread().getId();
        String jsonFilename = String.format("json:run/cucumber%d.json", threadId);

            String argv[] = new String[]{
                "--glue",
                "com.some.package",
                "--format",
                jsonFilename,
                "d:\\features"};

        // Do not call Main.run() directly. It has a System.exit() call at the end.             
        // Main.run(argv, Thread.currentThread().getContextClassLoader());

        // Copied the same code from Main.run(). 
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        RuntimeOptions runtimeOptions = new RuntimeOptions(new Env("cucumber-jvm"), argv);
        ResourceLoader resourceLoader = new MultiLoader(classLoader);
        ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
        Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
        runtime.writeStepdefsJson();
        runtime.run();      
Run Code Online (Sandbox Code Playgroud)

我试图为每个Cucumber运行创建一个单独的线程.问题是,只有一个线程有一个有效的JSON报告.所有其他线程只创建空JSON文件.这是黄瓜的设计还是我错过了什么?

Pet*_*vis 1

目前还没有——这是您观察到的问题。我还没有找到任何按场景并行化的方法。

这是一篇关于穷人并发性的精彩文章。只需运行多个命令,每个命令按功能或标签选择不同的测试子集。我会分叉一个新的 JVM(就像 JUnit 驱动程序那样),而不是尝试对其进行线程化,因为 Cucumber 不是为此设计的。您必须自己平衡它们,然后弄清楚如何合并这些报告。(但至少问题在于合并报告而不是损坏报告。)