aspose file tools*
The moose likes Testing and the fly likes JUnit 4 sampler for JMeter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit 4 sampler for JMeter" Watch "JUnit 4 sampler for JMeter" New topic
Author

JUnit 4 sampler for JMeter

rick simpson
Greenhorn

Joined: Oct 15, 2008
Posts: 8
Hi,

As far as I can tell the JUnit Sampler for JMeter only supports JUnit 3, not JUnit 4. The tests I'm trying to repurpose are all JU4 and I don't want to rewrite them in JU3 and have to maintain two test suites. I've tried swapping in the JUnit 4 jar but that didn't help.

Is there a way to use JU4 and JM together?

Thanks
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Rick,
I haven't used that particular feature, but I can provide a general comment. Do you have the source code for the JUnit Sampler? If so, can you change the line that calls JUnit to use the JUnit 4 Adapter?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Matt Hoffman
Ranch Hand

Joined: Jun 03, 2004
Posts: 83
Has anyone figured this out? I want to use JUnit 4 with Jmeter.
Brian Sweeney
Greenhorn

Joined: Sep 02, 2009
Posts: 2
From the mail lists, it seems the issue is that jmeter is based on java 1.4 and therefore can't use annotations. I don't think there is a quick fix out of the box. But if you download the code, the method used to find classes that extend TestCase is pretty clever and easy to copy/modify to into a method that finds methods annotated with @Test. I'm not sure how difficult it will be to construct and execute the tests because I haven't gotten that far, yet. Hopefully when I do, I can get it checked-in to a 1.5-specific branch.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Brian Sweeney wrote:From the mail lists, it seems the issue is that jmeter is based on java 1.4 and therefore can't use annotations. I don't think there is a quick fix out of the box. But if you download the code, the method used to find classes that extend TestCase is pretty clever and easy to copy/modify to into a method that finds methods annotated with @Test. I'm not sure how difficult it will be to construct and execute the tests because I haven't gotten that far, yet. Hopefully when I do, I can get it checked-in to a 1.5-specific branch.


Yep, it seems that it actually is taking less code to hunt down the @Before and @After annotations and invoke the test method.

And looking for @Test annotations to populate the drop down in the configurator page was not that hard either.

Haven't got it to work completely yet. Can't get all the results to work the way I want. I'll publish the results on my blogg when I do and tell you all.
Brian Sweeney
Greenhorn

Joined: Sep 02, 2009
Posts: 2
I've posted a patch to jmeter's bugzilla for review. Adoption will probably be slow since it will require a jar change. https://issues.apache.org/bugzilla/show_bug.cgi?id=47803 Download the source, apply the patch, and be on your way. Feedback is more than welcome, especially on the few outstanding issues mentioned in the bug report.
Dmitri Tikhanski
Greenhorn

Joined: Oct 13, 2013
Posts: 16
According to JMeter's changelog JUnit Sampler started supporting JUnit4-style annotations since version 2.4.

For advanced information on JUnit Request Sampler refer to How to Use JUnit With JMeter guide.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit 4 sampler for JMeter