Closed asfimport closed 14 years ago
Brian (migrated from Bugzilla): I forgot to mention that for this to all work, you'll need to be using a version of junit 4 instead of the junit 3.8.2 that normally comes with the current release of jmeter.
Sebb (migrated from Bugzilla): Thanks for the patch; I'll take a look at adding it soon.
Would it be possible to provide some example tests as well?
Brian (migrated from Bugzilla): Yes - working on that. But in doing so I realized that some of the changes that I made busted things for new test plans (I think my saved test plans that I was using to make sure I didn't break things were working - leading me astray). So I'm going to fix those issues today and re-submit. I'll tack a test case on there.
Brian (migrated from Bugzilla): My previous test included the prefix "test" on methods, which is why I didn't notice things were a bit broken. This includes a fix that allows arbitrarily named methods.
@Suite, @BeforeClass and @AfterClass aren't currently supported. It doesn't really seem to fit in with the framework of 1 test per sampler.
Created attachment annotations.patch: updated annotations patch
Brian (migrated from Bugzilla): Annotated test to exercise the new code. If you don't run setup/teardown on the add() test, it should fail. If you do run setup/teardown, it should work.
Created attachment DummyAnnotatedTest.java: test case using JUnit 4.x annotations
Sebb (migrated from Bugzilla): Thanks very much!
Two minor problems:
Would you mind fixing those please?
Also, if you get a chance, perhaps you could add some more Test annotations, e.g. expectedException and timeout, since these are handled by the code?
Brian (migrated from Bugzilla): Should flex the abilities of the patch that adds support for junit 4.x style tests
Created attachment DummyAnnotatedTest.java: annotated test cases
Brian (migrated from Bugzilla): Fixes a timeout bug.
Created attachment annotations.patch: updated annotations patch
Brian (migrated from Bugzilla): Added the apache license to another file where I'd left it off.
Created attachment annotations.patch: patch to support junit 4.x style annotated tests
Brian (migrated from Bugzilla):
Thanks for looking the patch over.
Sebb (migrated from Bugzilla): Thanks very much for the patches.
It was reasonably easy to merge the JUnit4 code with the existing JUnit3 code, so I just added a checkbox to the GUI to allow users to select JUnit4 rather than JUnit3 test cases. I think this is easier than having two separate samplers.
SVN checkins:
https://github.com/apache/jmeter/issues/2273 - Support for JUnit 4.x tests defined by annotations Merge code from JUnitAnnotatedSampler.java
URL: http://svn.apache.org/viewvc?rev=817404&view=rev Log: https://github.com/apache/jmeter/issues/2273 - Support for JUnit 4.x tests defined by annotations Fix bug: test element not updated if method/classname not defined
URL: http://svn.apache.org/viewvc?rev=817397&view=rev Log: https://github.com/apache/jmeter/issues/2273 - Support for JUnit 4.x tests defined by annotations Sample test cases
URL: http://svn.apache.org/viewvc?rev=816976&view=rev Log: Tidy up. Add hooks for JUnit4 GUI support
Brian (Bug 47803): The current version of jmeter doesn't recognize test cases specified by the @Test annotation for junit 4.x+. Support should be easy to support since junit 3 is already supported. Basically, an annotated test case sampler should look for the @Test annotation instead of classes that extend TestCase.
That's what I've done in the attached patch. The annotated sampler is an extension of the 3.x sampler. I've overridden the sample method and a couple of support methods to work with the new style tests. That causes a difference in behavior between instances of the 3.x and annotated samplers. I initially wanted to share the UI code and have it intelligently switch between 3.x and annotated instances, but the methods available didn't easily permit that. The choice was between adding a very limited new UI type or hiding the actual junit sampler instance behind a facade. It seemed more in keeping with other patterns to just make another UI class. That seems like a reasonable choice given that I expect users will know what they're trying to test (and which version of junit they depend on) before they start writing test plans.
There are 2 remaining details where I could use some help. First, I've added a resource key (junit_4_request=JUnit Annotated Request) that needs to be translated. I'm not sure what the process for that is. Second, in the saved test plan files, saves of my added class use the fully qualified name. Other classes seem to use short names. Everything seems to work okay for me, but there's probably a reason it looks different. I imagine that should be fixed.
Created attachment JUnitAnnotations.patch: Support for junit annotated test cases
OS: All