【问题标题】:Running a Junit Test Suite with Zerocode使用 Zerocode 运行 Junit 测试套件
【发布时间】:2020-02-27 15:50:27
【问题描述】:

我正在尝试使用 Zerocode 使用 Junit(4) 运行负载测试。按照这些教程,我能够运行现有的 Junit 测试类

我有一个正常工作的 Junit 测试套件,我想知道如何使用 zerocode 来启动这个测试套件,以便它运行所有测试类中的所有测试以进行负载测试。上面的示例仅描述了如何运行选定的测试方法或少数几个。

【问题讨论】:

    标签: java junit zerocode


    【解决方案1】:

    我认为你不能用 Zerocode 做到这一点。

    如果您想重用您的 JUnit 测试,您需要创建一个 LoadScenario 测试类。在这个类中,你需要告诉你要使用哪个测试以及它应该运行哪个方法。

    例如

    @LoadWith("load_generation.properties")
    @TestMapping(testClass = PostCorpLoanServiceTest.class, testMethod = "testPostNewLoan_crudOperations")
    @TestMapping(testClass = PutCorpLoanServiceTest.class, testMethod = "testPutAmendExistingLoan")
    @TestMapping(testClass = GetScreeningServiceTest.class, testMethod = "testGetScreeningLocalAndGlobal")
    @RunWith(ZeroCodeMultiLoadRunner.class)
    public class JunitParallelMultiScenarioTest {
    
    }
    
    

    看看托管在 github 上的这个 repo: https://github.com/authorjapps/performance-tests。 它是 ZeroCode 框架(框架的负载测试部分)的展示项目。它包含在 Zerocode 框架的帮助下创建的负载测试示例。

    【讨论】:

    • 感谢您的回复。我正在寻找一种无需单独指定方法即可运行测试的方法。无论如何,需要这部分的任务已经暂停了。如有进一步需要,将重新访问。
    【解决方案2】:

    您不需要 Zerocode 来实现这一点。您可以简单地使用Maven SureFire 插件来并行运行您的套件类(它引用了其他测试类)。

               <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M3</version>
                    <configuration>
                        <includes>
                            <include>org.jsmart.samples.tests.AnyTestSuite</include>
                        </includes>
                        <parallel>classes</parallel>
                        <!--<parallel>methods</parallel>--> <!-- Or use methods -->
                    </configuration>
                </plugin>
    

    注意: 在这种情况下,您需要确保您的所有测试方法/类实际上/潜在地可以并行运行。这意味着 - 就数据而言,您需要确保正确设计它们,使它们独立或不打算相互重叠或阻塞。

    这也适用于以下情况,但在这里您自己挑选测试,并确保它们可以输入并行运行器。

    1) 但是,如果您在各个测试类(而不是 Suite 类)上使用 @RunWith(ZeroCodeUnitRunner.class),那么您会在“目标”文件夹中获得一份不错的 CSV 报告。

    然后您可以使用此报告为您的项目或业务受众生成各种吞吐量graphs/statistics 等。请参阅此blog 中的Extract useful information from the data 部分。

    2) 如果您需要控制并行运行,例如如果您想触发 50 users in 60secs100 users in 60 secs1000 users in 300 secs 等,那么您需要 Zerocode 运行器来帮助您轻松实现这一目标。

    @RunWith(ZeroCodeLoadRunner.class)
    -or-
    @RunWith(ZeroCodeMultiLoadRunner.class)
    

    【讨论】:

    • 感谢您的回复。无论如何,需要这部分的任务已经暂停了。如有进一步需要,将重新访问。
    猜你喜欢
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 2013-02-11
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多