File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit 4 sampler for JMeter

 
rick simpson
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33716
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Matt Hoffman
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone figured this out? I want to use JUnit 4 with Jmeter.
 
Brian Sweeney
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Firefox Browser Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic