You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Jürgen Weber <jw...@jwi.de> on 2007/01/23 23:19:34 UTC

JUnit setUp() trap

Hi,

several JUnit tutorials (inclusive the sample at 
http://junit.sourceforge.net/javadoc/junit/framework/TestCase.html) show a

protected void setUp()

method.


The JUnitSampler looks for the setUp() method using getMethod() but this 
finds only __public__ methods. So when you have a protected setUp() in 
your testcase, JUnitSampler will almost silently not call it, there is 
only a harmless log line:

2007/01/23 13:18:11 WARN  - jmeter.protocol.java.sampler.JUnitSampler: 
unittest.UnitTestClientImpl.setUp()

try {
                return clazz.getClass().getMethod(method,new Class[0]);
            } catch (NoSuchMethodException e) {
                log.warn(e.getMessage());
            }

I think it were better if there was a [x] call setUp() and tearDown() on 
the gui and throw an exception if there is none or not found.

It cost me quite some time and remote debugging to find out, why my 
setUp() was not called.

Jürgen


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: JUnit setUp() trap

Posted by Peter Lin <wo...@gmail.com>.
thanks for checking that. I will update the docs tonight.

again, sorry about that. I just assumed people would make setUp/tearDown
public. it never occurred to me people might make it protected or private

peter

On 1/23/07, Jürgen Weber <jw...@jwi.de> wrote:
>
> Actually, the tutorial
> (http://jakarta.apache.org/jmeter/usermanual/junitsampler_tutorial.pdf)
> does not mention that setUp() has to be public.
>
> OK, I entered http://issues.apache.org/bugzilla/show_bug.cgi?id=41446
>
> Debugging was actually a bit difficult as I could not simply run jmeter
> as part of my Eclipse project as jmeter does some magic loading its
> classes so I had to remote debug.
> But never mind, I learned something ;-)
>
> Thanks for a great tool,
> Jürgen
>
> Peter Lin wrote:
> > the tutorial on the JUnit sampler states the setup and teardown method
> > need
> > to be public. please open a bugzilla to enhance the user manual.
> >
> > sorry you had to waste time debugging your test. it's generally better
> to
> > make the setup, teardown, onetimesetup and onetimeteardown public
> > methods.
> >
> > peter
> >
> > On 1/23/07, Jürgen Weber <jw...@jwi.de> wrote:
> >>
> >> Hi,
> >>
> >> several JUnit tutorials (inclusive the sample at
> >> http://junit.sourceforge.net/javadoc/junit/framework/TestCase.html)
> >> show a
> >>
> >> protected void setUp()
> >>
> >> method.
> >>
> >>
> >> The JUnitSampler looks for the setUp() method using getMethod() but
> this
> >> finds only __public__ methods. So when you have a protected setUp() in
> >> your testcase, JUnitSampler will almost silently not call it, there is
> >> only a harmless log line:
> >>
> >> 2007/01/23 13:18:11 WARN  - jmeter.protocol.java.sampler.JUnitSampler:
> >> unittest.UnitTestClientImpl.setUp()
> >>
> >> try {
> >>                 return clazz.getClass().getMethod(method,new Class[0]);
> >>             } catch (NoSuchMethodException e) {
> >>                 log.warn(e.getMessage());
> >>             }
> >>
> >> I think it were better if there was a [x] call setUp() and tearDown()
> on
> >> the gui and throw an exception if there is none or not found.
> >>
> >> It cost me quite some time and remote debugging to find out, why my
> >> setUp() was not called.
> >>
> >> Jürgen
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: JUnit setUp() trap

Posted by Peter Lin <wo...@gmail.com>.
I've updated the tutorial with a warning. thanks for catching that and
opening a bugzilla.

peter

On 1/23/07, Jürgen Weber <jw...@jwi.de> wrote:
>
> Actually, the tutorial
> (http://jakarta.apache.org/jmeter/usermanual/junitsampler_tutorial.pdf)
> does not mention that setUp() has to be public.
>
> OK, I entered http://issues.apache.org/bugzilla/show_bug.cgi?id=41446
>
> Debugging was actually a bit difficult as I could not simply run jmeter
> as part of my Eclipse project as jmeter does some magic loading its
> classes so I had to remote debug.
> But never mind, I learned something ;-)
>
> Thanks for a great tool,
> Jürgen
>
> Peter Lin wrote:
> > the tutorial on the JUnit sampler states the setup and teardown method
> > need
> > to be public. please open a bugzilla to enhance the user manual.
> >
> > sorry you had to waste time debugging your test. it's generally better
> to
> > make the setup, teardown, onetimesetup and onetimeteardown public
> > methods.
> >
> > peter
> >
> > On 1/23/07, Jürgen Weber <jw...@jwi.de> wrote:
> >>
> >> Hi,
> >>
> >> several JUnit tutorials (inclusive the sample at
> >> http://junit.sourceforge.net/javadoc/junit/framework/TestCase.html)
> >> show a
> >>
> >> protected void setUp()
> >>
> >> method.
> >>
> >>
> >> The JUnitSampler looks for the setUp() method using getMethod() but
> this
> >> finds only __public__ methods. So when you have a protected setUp() in
> >> your testcase, JUnitSampler will almost silently not call it, there is
> >> only a harmless log line:
> >>
> >> 2007/01/23 13:18:11 WARN  - jmeter.protocol.java.sampler.JUnitSampler:
> >> unittest.UnitTestClientImpl.setUp()
> >>
> >> try {
> >>                 return clazz.getClass().getMethod(method,new Class[0]);
> >>             } catch (NoSuchMethodException e) {
> >>                 log.warn(e.getMessage());
> >>             }
> >>
> >> I think it were better if there was a [x] call setUp() and tearDown()
> on
> >> the gui and throw an exception if there is none or not found.
> >>
> >> It cost me quite some time and remote debugging to find out, why my
> >> setUp() was not called.
> >>
> >> Jürgen
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: JUnit setUp() trap

Posted by Jürgen Weber <jw...@jwi.de>.
Actually, the tutorial 
(http://jakarta.apache.org/jmeter/usermanual/junitsampler_tutorial.pdf) 
does not mention that setUp() has to be public.

OK, I entered http://issues.apache.org/bugzilla/show_bug.cgi?id=41446

Debugging was actually a bit difficult as I could not simply run jmeter 
as part of my Eclipse project as jmeter does some magic loading its 
classes so I had to remote debug.
But never mind, I learned something ;-)

Thanks for a great tool,
Jürgen

Peter Lin wrote:
> the tutorial on the JUnit sampler states the setup and teardown method 
> need
> to be public. please open a bugzilla to enhance the user manual.
>
> sorry you had to waste time debugging your test. it's generally better to
> make the setup, teardown, onetimesetup and onetimeteardown public 
> methods.
>
> peter
>
> On 1/23/07, Jürgen Weber <jw...@jwi.de> wrote:
>>
>> Hi,
>>
>> several JUnit tutorials (inclusive the sample at
>> http://junit.sourceforge.net/javadoc/junit/framework/TestCase.html) 
>> show a
>>
>> protected void setUp()
>>
>> method.
>>
>>
>> The JUnitSampler looks for the setUp() method using getMethod() but this
>> finds only __public__ methods. So when you have a protected setUp() in
>> your testcase, JUnitSampler will almost silently not call it, there is
>> only a harmless log line:
>>
>> 2007/01/23 13:18:11 WARN  - jmeter.protocol.java.sampler.JUnitSampler:
>> unittest.UnitTestClientImpl.setUp()
>>
>> try {
>>                 return clazz.getClass().getMethod(method,new Class[0]);
>>             } catch (NoSuchMethodException e) {
>>                 log.warn(e.getMessage());
>>             }
>>
>> I think it were better if there was a [x] call setUp() and tearDown() on
>> the gui and throw an exception if there is none or not found.
>>
>> It cost me quite some time and remote debugging to find out, why my
>> setUp() was not called.
>>
>> Jürgen
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: JUnit setUp() trap

Posted by Peter Lin <wo...@gmail.com>.
the tutorial on the JUnit sampler states the setup and teardown method need
to be public. please open a bugzilla to enhance the user manual.

sorry you had to waste time debugging your test. it's generally better to
make the setup, teardown, onetimesetup and onetimeteardown public methods.

peter

On 1/23/07, Jürgen Weber <jw...@jwi.de> wrote:
>
> Hi,
>
> several JUnit tutorials (inclusive the sample at
> http://junit.sourceforge.net/javadoc/junit/framework/TestCase.html) show a
>
> protected void setUp()
>
> method.
>
>
> The JUnitSampler looks for the setUp() method using getMethod() but this
> finds only __public__ methods. So when you have a protected setUp() in
> your testcase, JUnitSampler will almost silently not call it, there is
> only a harmless log line:
>
> 2007/01/23 13:18:11 WARN  - jmeter.protocol.java.sampler.JUnitSampler:
> unittest.UnitTestClientImpl.setUp()
>
> try {
>                 return clazz.getClass().getMethod(method,new Class[0]);
>             } catch (NoSuchMethodException e) {
>                 log.warn(e.getMessage());
>             }
>
> I think it were better if there was a [x] call setUp() and tearDown() on
> the gui and throw an exception if there is none or not found.
>
> It cost me quite some time and remote debugging to find out, why my
> setUp() was not called.
>
> Jürgen
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>