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 {

        @Test
        @Repeat(times=20)
        public Item testJSONObject(@Param(name='itemId')String itemId, @Param(name='itemType')String itemType) {
           Item result = testSubject.findItem(itemId)
             Assert.notNull(result);
             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.

EasyTest_Repeat

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.

 

Do you want to know how to develop your skillset to 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!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


7 × = forty two



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
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:
Close