1

Does Jmeter supports Junit testsuite?
This question trouble me for several days, the test cases all working well no matter a style of junit 3 or 4. But the testsuite is anyway dumb.
Any suggestions?

My code below:

public class LoginLogout extends TestCase {
    private static Logger log = Logger.getLogger(LoginLogout.class);

    public static Test suite() {
        try{
            log.info("test suite start!");

            TestSuite suite = new TestSuite(LoginLogout.class.getName());
            //$JUnit-BEGIN$
            suite.addTestSuite(Login.class);
            suite.addTestSuite(Logout.class);

            return new TestSetup(suite) {
                protected void setUp(){
                    log.info("test suite setup!");
                }
                protected void tearDown(){
                    log.info("test suite finished!");
                }
            };
        }catch(Exception e){
            log.error(e.getMessage());
        }
        return null;
    }

}

public class Login extends TestCase {
    private static Logger log = Logger.getLogger(Login.class);
    @Test
    public void testLogin() throws Exception {
        log.info("login start!");
        log.info("login end!");
    }
}

public class Logout extends TestCase {
    private static Logger log = Logger.getLogger(Logout.class);
    @Test
    public void testLogout() throws Exception {
        log.info("logout start!");
        log.info("logout end!");
    }

}
Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
pangbuddy
  • 11
  • 1
  • 2
  • you're mixing up JUnit 3 and 4. delete the @Test Annotation in your Testcase. Maybe this fixes the Problem. Or you turn everything to JUnit 4. Another problem could be, that you extend TestCase in the class containing your suite()-Method – kirschmichel Oct 22 '12 at 09:27
  • I searched all relevant topics in Google, but no-one example of junit testsuite in Jmeter found, that's why i doubt it real exist. – pangbuddy Oct 22 '12 at 09:35

2 Answers2

1

You can go to "Download Apache JMeter" page on http://jmeter.apache.org/ , and download the "apache-jmeter-2.8_src.zip" (or whatever the current version is).

After unzipping it, under apache-jmeter-2.8_src\apache-jmeter-2.8\src\junit\test directory, you can find the following java files (as for jmeter version 2.8):

For JUnit4:

AfterAnnotatedTest.java
BeforeAnnotatedTest.java
DummyAnnotatedTest.java
Junit4AnnotationsTest.java

For JUnit3:

RerunTest.java
SetupTestError.java
SetupTestFail.java
TearDownTestFail.java

You can see them shown up at the Classname dropdown menu on JUnit Request of JMeter (Test Plan --> Thread Group --> JUnit Request).

Those JUnit test cases are provided by JMeter by default, so I assume that a simple copy-and-paste of their code and work from there should work; however, so far, I am not able to see my test cases shown up at the Classname dropdown menu.

Here are other useful links I have found; however, none of them solves the current problem I am encountering:

Community
  • 1
  • 1
Martin
  • 11
  • 2
  • also this link: http://www.anzaan.com/2012/07/integrating-selenium-with-jmeter-for-application-load-testing/ – Martin Jan 10 '13 at 01:19
  • I have resolved the issue: "so far, I am not able to see my test cases shown up at the Classname dropdown menu." (as stated above) Instead of using "mvn install" (via a pom.xml) to create the test case jar file, I simply used the "Export" functionality of Eclipse IDE to create the jar file (not Runnable Jar, just a regular Jar), and then copied the newly created jar file to "\src\junit" sub-folder of the JMeter installation directory. – Martin Jan 10 '13 at 18:28
0

For JUnit4 the Suite would be:

@RunWith(Suite.class)
@SuiteClasses({Login.class, Logout.class})
public class LoginLogout {
  private static Logger log = Logger.getLogger(LoginLogout.class.getName());
}

And the TestClass is:

public class Login {
    private static Logger log = Logger.getLogger(Login.class.getName());
    @Test
    public void testLogin() throws Exception {
        log.info("login start!");
        log.info("login end!");
    }
}

Worked fine for me

kirschmichel
  • 903
  • 1
  • 8
  • 14
  • Do you mean it worked in Jmeter? it was my initial trying, but it looks Jmeter doesn't support testsuite in Junit 4 style, the @RunWith annotation seems can't be recognised. – pangbuddy Oct 22 '12 at 09:50
  • I haven't tried it with JMeter, but according to this [link](http://jmeter.apache.org/changes_history.html) JUnit 4 should be provided by JMeter – kirschmichel Oct 22 '12 at 10:39