pangbuddy
pangbuddy

Reputation: 11

Junit testsuite in Jmeter

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!");
    }

}

Upvotes: 1

Views: 5901

Answers (2)

Martin
Martin

Reputation: 11

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:

Upvotes: 1

kirschmichel
kirschmichel

Reputation: 923

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

Upvotes: 0

Related Questions