-
-
Notifications
You must be signed in to change notification settings - Fork 403
JUnit5 Jupiter Parallel Load Extension
-
Table of Contents
- Parallel Running as well as, Load and Stress Testing of JUnit5 tests
- Maven Dependencies
- Existing JUnit5 tests
- Generating Load
- What does JUnit5LoadTest example do?
- What does JUnit5LoadCommonLoadTest example do?
- What does JUnit5LoadDifferentLoadTest example do?
- Reports
- Running the Load tests as a Suite
- GitHub Repo - Examples
/src/test/java/.../samplesjunit5/jupiter/JUnit5Test.java
@ExtendWith({ExtensionA.class, ExtensionB.class}) //<--- Just for demonstration purpose
public class JUnit5Test {
@Test
public void testX() {
assertTrue(2 == 2); //<--- jupiter assertion
}
@Test
public void testY() throws InterruptedException {
assertTrue(2 == 2); //<--- jupiter assertion
}
}
/src/test/java/.../samplesjunit5/jupiter/JUnit5MoreTest.java
@ExtendWith({ExtensionA.class, ExtensionB.class})
public class JUnit5MoreTest {
@Test
public void testZ() throws InterruptedException {
assertTrue(2 == 2); //jupiter assertion
}
}
/src/test/java/org/jsmart/zerocode/samplesjunit5/loadjupiter/simpleload/JUnit5LoadTest.java
@LoadWith("load_generation.properties")
@ExtendWith({ParallelLoadExtension.class})
public class JUnit5LoadCommonLoadTest {
@Test
@DisplayName("testing parallel load for X, Y and Z scenarios")
@TestMappings({
@TestMapping(testClass = JUnit5Test.class, testMethod = "testX"),
@TestMapping(testClass = JUnit5Test.class, testMethod = "testY"),
@TestMapping(testClass = JUnit5MoreTest.class, testMethod = "testZ")
})
public void testLoad_xyz() {
// This space remains empty
}
}
- Add the following dependencies JUnit5/Jupiter Extension
<dependency>
<groupId>org.jsmart</groupId>
<artifactId>zerocode-tdd-jupiter</artifactId>
<version>1.3.7</version> <!-- or higher -->
</dependency>
Maven maven-surefire-plugin
version
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- or higher -->
</dependency>
In the
HelloWorld
performance test repo, the below are the JUnit5 tests
Or we can alternatively say - Running the tests in parallel as configured
- This generates load as configured in the
@LoadWith("load_generation.properties")
- If your load generation configuration is same for all kind of load you are setting up to generate, then
you can annotate the config at the
Class
level@LoadWith("load_generation.properties")
e.g.
@LoadWith("load_generation.properties")
@ExtendWith({ParallelLoadExtension.class})
public class JUnit5LoadCommonLoadTest {
//...
}
- If your load generation configuration is different for different kind of load you are setting up to generate, then, you need to annotate the config at the
Method
level@LoadWith("load_generation.properties")
e.g.,
- Two tests below run in parallel 1)"testX" 2)"testY"
@ExtendWith({ParallelLoadExtension.class})
public class JUnit5LoadDifferentLoadTest {
@Test
@DisplayName("1sec gap per user - Firing parallel load for X and Y scenarios")
@TestMappings({
@TestMapping(testClass = JUnit5Test.class, testMethod = "testX"),
@TestMapping(testClass = JUnit5Test.class, testMethod = "testY")
})
@LoadWith("load_generation.properties")
public void testLoad_xy() {
// This space remains empty
}
- The below configuration means, two
users
firing the requests in parallel with2 sec
gap.
number.of.threads=2
ramp.up.period.in.seconds=4
loop.count=1
You can manipulate this to match your parallel-run/load requirement e.g.
number.of.threads=50
ramp.up.period.in.seconds=50
loop.count=2
which means, 50 users
firing the requests in parallel with 1 sec
gap and they repeat twice
. That leads to 100 users
firing tests in parallel within 100 sec
. Visit here to know How to Manipulate the config
- This generates CSV report only which is useful and efficient for tracing the failures
- We have deliberately suppressed the HTML reports as they are not particularly useful for load tests
- CSV gives us flexibility to
slice n dice
for analysis purpose. - Using CSV we can generate various throughput, 2D, 3D metrices of our performance testing
- This setup(JUnit5LoadDifferentLoadTest, JUnit5LoadCommonLoadTest) is already like a Suite setup
- which means you don't need another Suite-Runner
- Nevertheless there will be always situations to bring up a load suite.
- So we have put an example here to get you covered, which looks like below.
@RunWith(JUnitPlatform.class)
@IncludeEngines("junit-jupiter")
@SelectPackages("org.jsmart.zerocode.samplesjunit5.loadjupiter")
public class ParallelLoadTestSuite {
// Nothing goes in this space
}
- The regular
Junit
tests and theload
generating tests are here - You can clone this repo and run from your IDE
- Please note- Junit5/Jupiter tests and JUnit4 tests can exist together.
- Which means - Junit4 tests run via the Vintage engine
- That's not really an issue to maintain both tests, as explained here JUnit5 user-guide
Which reads : Since all classes and annotations specific to JUnit Jupiter reside under a new org.junit.jupiter base package, having both JUnit 4 and JUnit Jupiter in the classpath does not lead to any conflicts.
Visit the Zerocode Documentation Site for all things.
-
User's Guide
-
Matchers
-
Zerocode Value Tokens
-
YAML DSL
-
Http Testing
-
Kafka Testing
- Introduction
- Produce, consume proto message
- Produce raw message
- Consume raw message
- Produce JSON message
- Consume JSON message
- Produce and consume XML message
- Kafka - consume the latest message or n latest messages
- Produce avro message
- Consume avro message
- KSQL in action
- Produce multiple records
- Produce from file
- Produce to a partition
- Produce and consume records with headers
- Produce n assert partition ack
- Comsume and dump to file
- commitSync vs commitAsync
- Overriding config inside a test
- Chosing String or Int or Avro Serializer
- Chosing String or Int or Avro Deserializer
- Attaching timestamp during load
- Default timestamp provided by Kafka
- Consume and assert avro schema metadata
- Error handling - produce via avro schema
- Sorting Kafka records consumed
-
DB Testing
-
Kotlin Testing
-
Performance Testing - Load and Stress
- Performance Testing - via awesome JUnit runners
- Load Vs Stress generation on target application
- Run a single test or a scenario in parallel
- Run multiple test scenarios in parallel - Production load simulation
- Dynamically change the payload for every request
- Analytics - Useful report(s) or statistics
-
Parameterized Testing
-
Docker
-
More+
-
Extensions
-
JUnit5 Jupiter Test
-
Questions And Answers(FAQ)
- What is Zerocode testing?
- SSL http https connections supported?
- How to assert array size Greater-Than Lesser-Than etc?
- How to invoke POST api?
- How to assert custom headers of the response?
- How to pass custom security token into the request header?
- When to use JUnit Suite runner and when Zerocode Package runner?
- How to execute DB SQL and assert?
- How to handle Http response other than utf-8 e.g. utf-16 or utf-32 ?
- Random Number Generator Placeholders Usages and Limits
- Automation tests for Zerocode lib itself
- Picking a leaf value from the array matching JSON Path
- Array assertions made easy, incl. size and element finder
-
Read Our Blogs
- Top 16 Open Source API Testing Tools For REST & SOAP Services - joecolantonio (Lists popular tools - Globally)
- OAuth2 Test Automation - DZone 2min Read
- Zero defect APIs - Build Pipe Line - Medium 10 min Read
- Develop ZeroDefect API's with ZeroCode! - Extreme Portal ( A must read for all developers and test engineers) 10min Read
- Performance testing using JUnit and maven - Codeproject 10 min Read
- REST API or SOAP End Point Testing - Codeproject 10min Read
- DZone- MuleSoft API Testing With Zerocode Test Framework - DZone 5min Read
- Testing need not be harder or slower, it should be easier and faster - DZone 5 min Read
- Kotlin Integration Testing simplified via Zerocode - Extreme portal 10 min Read
- and More...