Skip to content

Latest commit

 

History

History
214 lines (183 loc) · 7.83 KB

README.md

File metadata and controls

214 lines (183 loc) · 7.83 KB

Table of Contents

Performance testing (Testing load and stress)

Sample Performance Tests - Banking (Using JUnit and Zerocode test framework)

Maven dependencies - JUnit5 Jupiter Tests

<dependency>
    <groupId>org.jsmart</groupId>
    <artifactId>zerocode-tdd-jupiter</artifactId>
    <version>1.3.23</version> <!-- or higher -->
</dependency>

Then follow this WikiPage.

For JUnit4 parallel-run or load testing, follow the samples in the below sections.

Maven dependencies - JUnit4

<dependency>
    <groupId>org.jsmart</groupId>
    <artifactId>zerocode-tdd</artifactId>
    <version>1.3.23</version> 
</dependency>

Prepare Scenario

Single scenario parallel load

See this GET load test in the repo e.g.

@LoadWith("load_generation.properties")
@TestMapping(testClass = GetScreeningServiceTest.class, testMethod = "testGetScreeningLocalAndGlobal")
@RunWith(ZeroCodeLoadRunner.class)
public class LoadGetTest {

}

Where, the load_generation.properties has the below load e.g.
(100 requests in 100secs i.e. each request in 1 sec gap, looping twice, meaning 200 parallel requests)

number.of.threads=100
ramp.up.period.in.seconds=100
loop.count=2

It generates load for the below GET scenario:

@TargetEnv("screening_service_host.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class GetScreeningServiceTest {

    @Test
    @JsonTestCase("load_tests/get/get_screening_details_by_custid.json")
    public void testGetScreeningLocalAndGlobal() throws Exception {
    }
}

Where the get_screening_details_by_custid.json with payload and assertions/validations :

{
    "scenarioName": "Screening API- Get Screening by customerId test",
    "steps": [
        {
            "name": "get_screening_details",
            "url": "/api/v1/screening/cust-ids/SINGAHV3033",
            "method": "GET",
            "request": {
            },
            "verify": {
                "status": 200,
                "body": {
                    "id" : "SINGAHV3033",
                    "localScreeningStatus" : "Green",
                    "globalScreeningStatus" : "Red"
                }
            }
        }

    ]
}

Combining single loads(GET, POST, PUT etc)

See the suite test firing different loads with single scenario each e.g. sample test-class: org.jsmart.zerocode.samples.load.LoadTestSuite

@Suite.SuiteClasses({

        LoadGetTest.class,
        LoadPostTest.class,
        LoadMultipleGetPostPutTest.class

})
@RunWith(Suite.class)
public class LoadTestSuite {

}

Multi scenario parallel load

See the test-class org.jsmart.zerocode.samples.load.parallelmulti.LoadMultipleGetPostPutTest

/**
 * What's new in ZeroCodeMultiLoadRunner.class ?
 * ---------------------------------------------
 * While running with "ZeroCodeMultiLoadRunner.class", each test mapping here is equivalent to one user,
 * that means there are 3 concurrent users below invoking their respective user operations as:
 *         User-1) POST,GET
 *         User-2) PUT,GET
 *         User-3) GET
 *         User-N) so on
 *
 * Note :
 * ------
 * All 3 users are running in parallel which resembles the production like scenario where each user
 * doing different jobs.
 *
 * You can keep feeding/adding as many tests by using @TestMapping(TestClassName.class, "testMethodName")
 *
 * Please make sure you set "number.of.threads" >= "number of test mappings(= 3 here)" giving chance for
 * each scenario to get executed at least once.
 *
 */
@LoadWith("load_generation.properties")
@TestMapping(testClass = GetScreeningServiceTest.class, testMethod = "testGetScreeningLocalAndGlobal")
@TestMapping(testClass = PostCorpLoanServiceTest.class, testMethod = "testPostNewLoan_crudOperations")
@TestMapping(testClass = PutCorpLoanServiceTest.class, testMethod = "testPutAmendExistingLoan")
@RunWith(ZeroCodeMultiLoadRunner.class)
public class LoadMultipleGetPostPutTest {

}

(Optionally)Grouping the multiload tests

You can(optionally) group the @TestMappings as below for better readability and pretty looking too.

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

Load with gradually increasing or decreasing

See the test-class org.jsmart.zerocode.samples.loadgradually.LoadGraduallyTestSuite

@Suite.SuiteClasses({

        LoadGet1Per5SecTest.class, // <-- Less load (5 sec gap)
        LoadGet1Per1SecTest.class, // <-- Bit more load (1 sec gap)
        LoadGet5Per1SecTest.class  // <-- Heavy load (0.2 sec gap)

})
@RunWith(Suite.class)
public class LoadGraduallyTestSuite {

}
  • Download this project to run using your local IDE

Maven library used

  • Latest release (includes Kafka testing):
<dependency>
    <groupId>org.jsmart</groupId>
    <artifactId>zerocode-tdd</artifactId>
    <version>1.3.x</version> 
</dependency>

Disabling long-running HTML Reports

The Interactive-Html-Report generation is enabled by default. For load testing this report may not be quite useful as we are mostly interested in load statistics which we can get from the CSV reports. Also the HTML interactive reports particularly takes bit longer to generate during load testing.

To disable this report generation please use the following flag in the host properties file annotated with @TargetEnv("app_host_sit.properties").

interactive.html.report.disabled=true