About Anuj Kumar

Anuj is working as a Senior S/W Engineer in Netherlands. He is a Sun Certified Java Professional with experience in design and development of mid/large scale Java applications. He is the creator of EasyTest Framework(https://github.com/EaseTech) which is a Data Driven Testing Framework for Java.

Write effective Load Tests using JUnit and Repeat annotation

EasyTest recently introduced a new set of annotations that would help its users write effective test cases. The two main annotations that found their way into EasyTest are :

  • Repeat
  • Duration

Today we will discuss about the Repeat annotation.

A new method level annotation

Repeat has been added to the EasyTest Framework. This annotation can be used to repeat the same test multiple times. This annotation is useful in scenarios where you may quickly want to load test your application. Here is how this annotation can be used.

public class TestJSON {

        public Item testJSONObject(@Param(name='itemId')String itemId, @Param(name='itemType')String itemType) {
           Item result = testSubject.findItem(itemId)
             return result;

Notice the Repeat annotation at the method level. When EasyTest sees this annotation, it creates “n” different instances of the test method, where “n” is defined by the “times” attribute of the Repeat annotation. In the above case, EasyTest will create 20 unique instances of the above test method.

There is also a System Property test.repeatCount that can be used while running tests from command line. When this property is set, EasyTest simply creates “n” instances of each test defined in the test class, where “n” is defined by the value of the above System Property. System Property takes precedence over Repeat annotation. It means that if both annotation and system property is present, then System Property’s value will be used.

In case you have 3 set of input test data defined for a given test method which has a Repeat annotation with times = 20, the test will be run 20 times for each input test data. Thus total times that the test will run is 3 X 20 = 60.

This is a really quick and effective way to load test your application without any specific setup. Be aware that this alone cannot give you a true picture of your environment, but it can definitely be a good starting point.

When run on the IDE, each test case name will be appended with “_n” where n ranges from 0 till (times – 1), where times is the number specified in the Repeat annotation. Here is a screen shot for reference.


Thus as you can see, EasyTest provides the users with an quick and effective way of converting their existing unit tests into a load test with just the use of a single annotation.

In the next blog post we will discuss Duration annotation.


Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply

seven − = 1

Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below: