JUnit 4 – Executing multiple Test Suites

by seetaram on April 16, 2011

So far we have learnt JUnit 4 from the aspect of running a single test case.  In this post, we will explore how to run multiple test cases with JUnit 4.

I am less bothered about how the JUnit is used for unit testing, but my concern is how we can utilize JUnit (referring to JUnit 4) for functional testing along with Selenium.  We will learn executing multiple test cases using JUnit with a simple test.

Note: If you are a newbie to Selenium / JUnit / Eclipse, then please refer to my previous posts that explain various topics such as Setting up Eclipse with Selenium, Creating test cases in Eclipse, etc.

Let us write three simple tests and then using @RunWith and @SuiteClasses annotations we will execute all of them together as a TestSuite.

  1. Create a new Package (e.g. com.selftechy.testsuite)
  2. Create three JUnit Test Cases in Eclipse under this package (First, Second, and Third)
  3. Create a fourth JUnit test case as RunTestSuite
  4. Right Click on RunTestSuite –> Run As –> JUnit Test
  5. Console output should be as in the below picture




Create three JUnit test cases First, Second, Third, and RunTestSuite using the below code and execute RunTestSuite

package com.selftechy.testsuite;
import org.junit.Test;

public class First {
    public void testOne(){
        System.out.println("Executing first test");

package com.selftechy.testsuite;
import org.junit.Test;

public class Second {
    public void testTwo(){
        System.out.println("Executing second test");

package com.selftechy.testsuite;

import org.junit.Test;

public class Third {
    public void testThree(){
        System.out.println("Executing third test");

package com.selftechy.testsuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

public class RunTestSuite {

{ 21 comments… read them below or add one }

Sowmya May 12, 2011 at 11:45 am

Thanks for the information about Selenium and Eclipse.. You sure have made the life easy for newbies in Selenium and Eclipse.. Keep posting more..

Best Regards,


seetaram May 13, 2011 at 12:50 pm

Thanks Sowmya


Harry Soehalim June 22, 2011 at 5:03 am

you should change the subject to: Executing Multiple Test Suites


seetaram June 23, 2011 at 6:19 am

Yes…thanks for your suggestion.. What you told is correct… I will do that…


ajit July 27, 2011 at 12:13 pm

Thanks for sharing this information….

I would like to know “How to execute multiple test cases simultaneously” using Junit and selenium.


seetaram July 27, 2011 at 2:21 pm


If it is “test cases” then keep all the tests (ideally test methods in a java class that start with “test” – testGoogleAdvancedSearch) in the class and then Run As –> Junit Test

This will easily run all the tests in the class


Biswabrata Banerjee August 20, 2011 at 10:30 am

very neat and clean. keep up the good work. best wishes….


seetaram August 20, 2011 at 6:51 pm

Thank you…


SHIVAM September 23, 2011 at 7:35 am

This is the best explanation I ever had. Really good work….


seetaram September 23, 2011 at 11:45 am

Thank you Shivam


A.K Ramesh October 25, 2011 at 1:15 pm

could you tell me the diff b/n click and clickAt in selenium RC.
When to use it.


seetaram October 25, 2011 at 2:22 pm

Please refer the below link that explains the difference between click & clickAt:


Anita November 3, 2011 at 11:27 am

Nice Post :)…very informative


Jyothi November 22, 2011 at 9:32 am


Can you please explain the same thing without using eclipse? I would like to run the same tests from the command prompt.



Kewal Nautiyal December 19, 2013 at 11:09 am

Hi Jyothi,

You can run tests from command line as :

For a single Test:
adb shell am instrument -e -w /android.test.InstrumentationTestRunner

For all your Tests:
adb shell am instrument -w /android.test.InstrumentationTestRunner


Mahesh December 13, 2011 at 7:00 pm

Excellent work Seetaram. Keep it a Good work


seetaram December 14, 2011 at 12:22 pm

Thanks Mahesh


Ramya December 26, 2011 at 9:58 pm

Very nice work….keep it up….


Vinu July 17, 2012 at 5:32 am

Hi Seetaram,

I have automated few test cases and saved them into different test suites based on their respective areas (like..all login test cases in Login folder, all Registration into registration folder, all product test cases into Product folder etc…) now I want to run these test suite all at once using Ant.
Can anyone guide me how to do this.
I am able to run individual test suite by creating a testsuite.java class and in that class I am using the annotations

@Suite.SuiteClass({ ,

and calling this single test suite in the build.xml file
The above case works fine when I run individual test suite. But how to call multiple test suites in the scenario which I mentioned.



mani October 25, 2012 at 12:02 pm


This information is useful. But I have query.
Here how can I give first.class and second.class dynamically


in SuitesClasses annotation. I want to pass class names dynamically. Is it possible?


vijay September 22, 2016 at 9:03 pm

if First.class takes 3 minutes second.class takes 3 minutes and Third.class takes three minutes i wish not to wait 9 minutes but be able to run three parallel threads can anyone suggest how to accomplish same


Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email