Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

junit · JUnit, the Java unit testing framework written by Kent Beck and Erich Gamma.

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 31225
  • Category: Java
  • Founded: Nov 6, 2000
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Messages

Advanced
Messages Help
Messages 23094 - 23123 of 24386   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#23094 From: "David" <davids@...>
Date: Wed Dec 1, 2010 7:07 am
Subject: Re: Running JUnit tests from a separate Java application
dljande
Send Email Send Email
 
When I put a construct like this into my code

try {
     Result run = core.run(Request.method(Try.class, actionWord));
}
catch (NoTestsRemainException ex) {}

Java tells me
'Unreachable catch block for NoTestsRemainException. This exception is never
thrown from the try statement body'

If I generalise the last catch to look for ANY exception the catch never catches
because the run request always returns normally.

David
--- In junit@yahoogroups.com, David Saff <david@...> wrote:
>
> If the test case doesn't exist, I think the failure exception should
> be a NoTestsRemainException.  Can you check for that?
>
>    David Saff
>
> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@...> wrote:
> > I had hoped I could differentiate between a failed testcase and a failure
because the testcase does not exist.
> >
> > David
> >
> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >>
> >> That's the behavior I expect.  What were you expecting to see?
> >>
> >>    David Saff
> >>
> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
> >> > I had hoped so but with
> >> >
> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
> >> > System.out.println("Test result: " + run.wasSuccessful() );
> >> >
> >> > I get run.wasSuccessful() returning false when the method fails or it
does not exist.
> >> >
> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >>
> >> >> I think that if methodA does not exist, you will get an error message.
> >> >>  Do you see different behavior?
> >> >>
> >> >>    David
> >> >>
> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
> >> >> > Hi,
> >> >> >
> >> >> > Fantastic advice!
> >> >> >
> >> >> > I would also like to tell whether the methodA was actually executed
i.e. does it exist.
> >> >> >
> >> >> > Thanks,
> >> >> > David
> >> >> >
> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >>
> >> >> >> David,
> >> >> >>
> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class, "methodA"));
> >> >> >> 2) You can't both extend from TestCase and mark your tests with
@Test.
> >> >> >>  Remove the extends TestCase, and more things will work.
> >> >> >>
> >> >> >> Good luck,
> >> >> >>
> >> >> >>    David
> >> >> >>
> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
> >> >> >> > In Eclipse I have a project with a package and all my source code
is in the one package.
> >> >> >> >
> >> >> >> > I would like to run JUnit test cases selectively from a separate
Java application where I run the code
> >> >> >> >        org.junit.runner.JUnitCore.main("example.Try.methodA");
> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit test
module which looks like this:
> >> >> >> >
> >> >> >> > package example;
> >> >> >> >
> >> >> >> > import org.junit.*;
> >> >> >> > import junit.framework.TestCase;
> >> >> >> >
> >> >> >> > public class Try extends TestCase
> >> >> >> > {
> >> >> >> >        public Try(String name) {
> >> >> >> >                super(name);
> >> >> >> >        }
> >> >> >> >
> >> >> >> >        @Before
> >> >> >> >        public void baseState() {
> >> >> >> >        }
> >> >> >> >
> >> >> >> >        @Test
> >> >> >> >        public void methodA() {
> >> >> >> >        }
> >> >> >> >
> >> >> >> > }
> >> >> >> >
> >> >> >> > I get the error message 'Could not find class: example.Try.methodA'
> >> >> >> >
> >> >> >> > If I run Try.java as a JUnit Test I get the error
> >> >> >> > junit.framework.AssertionFailedError: No tests found in example.Try
> >> >> >> >
> >> >> >> >
> >> >> >> > David
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > ------------------------------------
> >> >> >> >
> >> >> >> > Yahoo! Groups Links
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > ------------------------------------
> >> >> >
> >> >> > Yahoo! Groups Links
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> > ------------------------------------
> >> >
> >> > Yahoo! Groups Links
> >> >
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>

#23095 From: David Saff <david@...>
Date: Wed Dec 1, 2010 1:54 pm
Subject: Re: Re: Running JUnit tests from a separate Java application
dsaff
Send Email Send Email
 
Sorry, could have given more information.

Result run = core.run(Request.method(Try.class, actionWord));
if (run.wasSuccessful())
   return "success!";
if (run.getFailures().getException() instanceof NoTestsRemainException)
   return "No such method!";
else
   return "Failed for another reason!";

On Wed, Dec 1, 2010 at 2:07 AM, David <davids@...> wrote:
> When I put a construct like this into my code
>
> try {
>    Result run = core.run(Request.method(Try.class, actionWord));
> }
> catch (NoTestsRemainException ex) {}
>
> Java tells me
> 'Unreachable catch block for NoTestsRemainException. This exception is never
thrown from the try statement body'
>
> If I generalise the last catch to look for ANY exception the catch never
catches because the run request always returns normally.
>
> David
> --- In junit@yahoogroups.com, David Saff <david@...> wrote:
>>
>> If the test case doesn't exist, I think the failure exception should
>> be a NoTestsRemainException.  Can you check for that?
>>
>>    David Saff
>>
>> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@...> wrote:
>> > I had hoped I could differentiate between a failed testcase and a failure
because the testcase does not exist.
>> >
>> > David
>> >
>> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >>
>> >> That's the behavior I expect.  What were you expecting to see?
>> >>
>> >>    David Saff
>> >>
>> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
>> >> > I had hoped so but with
>> >> >
>> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
>> >> > System.out.println("Test result: " + run.wasSuccessful() );
>> >> >
>> >> > I get run.wasSuccessful() returning false when the method fails or it
does not exist.
>> >> >
>> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >>
>> >> >> I think that if methodA does not exist, you will get an error message.
>> >> >>  Do you see different behavior?
>> >> >>
>> >> >>    David
>> >> >>
>> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
>> >> >> > Hi,
>> >> >> >
>> >> >> > Fantastic advice!
>> >> >> >
>> >> >> > I would also like to tell whether the methodA was actually executed
i.e. does it exist.
>> >> >> >
>> >> >> > Thanks,
>> >> >> > David
>> >> >> >
>> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >>
>> >> >> >> David,
>> >> >> >>
>> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class, "methodA"));
>> >> >> >> 2) You can't both extend from TestCase and mark your tests with
@Test.
>> >> >> >>  Remove the extends TestCase, and more things will work.
>> >> >> >>
>> >> >> >> Good luck,
>> >> >> >>
>> >> >> >>    David
>> >> >> >>
>> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
>> >> >> >> > In Eclipse I have a project with a package and all my source code
is in the one package.
>> >> >> >> >
>> >> >> >> > I would like to run JUnit test cases selectively from a separate
Java application where I run the code
>> >> >> >> >        org.junit.runner.JUnitCore.main("example.Try.methodA");
>> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit test
module which looks like this:
>> >> >> >> >
>> >> >> >> > package example;
>> >> >> >> >
>> >> >> >> > import org.junit.*;
>> >> >> >> > import junit.framework.TestCase;
>> >> >> >> >
>> >> >> >> > public class Try extends TestCase
>> >> >> >> > {
>> >> >> >> >        public Try(String name) {
>> >> >> >> >                super(name);
>> >> >> >> >        }
>> >> >> >> >
>> >> >> >> >        @Before
>> >> >> >> >        public void baseState() {
>> >> >> >> >        }
>> >> >> >> >
>> >> >> >> >        @Test
>> >> >> >> >        public void methodA() {
>> >> >> >> >        }
>> >> >> >> >
>> >> >> >> > }
>> >> >> >> >
>> >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
>> >> >> >> >
>> >> >> >> > If I run Try.java as a JUnit Test I get the error
>> >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > David
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > ------------------------------------
>> >> >> >> >
>> >> >> >> > Yahoo! Groups Links
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > ------------------------------------
>> >> >> >
>> >> >> > Yahoo! Groups Links
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > ------------------------------------
>> >> >
>> >> > Yahoo! Groups Links
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>> >
>>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23096 From: "David" <davids@...>
Date: Wed Dec 1, 2010 11:59 pm
Subject: Re: Running JUnit tests from a separate Java application
dljande
Send Email Send Email
 
Hi,

A glimmer of hope - exceptions from my test run are being caught.
Refer to this code snippet:

if (run.wasSuccessful())
    System.out.println("Result: " + run.wasSuccessful());
else if (run.getFailures().get(0).getException() instanceof
NoTestsRemainException)
{
    System.out.println("Method does not exist");
}
else {
    for (int i=0; i< run.getFailureCount(); i++)
	 System.out.println("Error ("+i+"): " +
run.getFailures().get(i).getException().getMessage());
}

When run do not see 'Method does not exist' being reported. All output is
stemming from the last 'else'.

How can I found out what exceptions are possible?

David

--- In junit@yahoogroups.com, David Saff <david@...> wrote:
>
> Sorry, could have given more information.
>
> Result run = core.run(Request.method(Try.class, actionWord));
> if (run.wasSuccessful())
>   return "success!";
> if (run.getFailures().getException() instanceof NoTestsRemainException)
>   return "No such method!";
> else
>   return "Failed for another reason!";
>
> On Wed, Dec 1, 2010 at 2:07 AM, David <davids@...> wrote:
> > When I put a construct like this into my code
> >
> > try {
> >    Result run = core.run(Request.method(Try.class, actionWord));
> > }
> > catch (NoTestsRemainException ex) {}
> >
> > Java tells me
> > 'Unreachable catch block for NoTestsRemainException. This exception is never
thrown from the try statement body'
> >
> > If I generalise the last catch to look for ANY exception the catch never
catches because the run request always returns normally.
> >
> > David
> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >>
> >> If the test case doesn't exist, I think the failure exception should
> >> be a NoTestsRemainException.  Can you check for that?
> >>
> >>    David Saff
> >>
> >> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@> wrote:
> >> > I had hoped I could differentiate between a failed testcase and a failure
because the testcase does not exist.
> >> >
> >> > David
> >> >
> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >>
> >> >> That's the behavior I expect.  What were you expecting to see?
> >> >>
> >> >>    David Saff
> >> >>
> >> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
> >> >> > I had hoped so but with
> >> >> >
> >> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
> >> >> > System.out.println("Test result: " + run.wasSuccessful() );
> >> >> >
> >> >> > I get run.wasSuccessful() returning false when the method fails or it
does not exist.
> >> >> >
> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >>
> >> >> >> I think that if methodA does not exist, you will get an error
message.
> >> >> >>  Do you see different behavior?
> >> >> >>
> >> >> >>    David
> >> >> >>
> >> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
> >> >> >> > Hi,
> >> >> >> >
> >> >> >> > Fantastic advice!
> >> >> >> >
> >> >> >> > I would also like to tell whether the methodA was actually executed
i.e. does it exist.
> >> >> >> >
> >> >> >> > Thanks,
> >> >> >> > David
> >> >> >> >
> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >> >>
> >> >> >> >> David,
> >> >> >> >>
> >> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class,
"methodA"));
> >> >> >> >> 2) You can't both extend from TestCase and mark your tests with
@Test.
> >> >> >> >>  Remove the extends TestCase, and more things will work.
> >> >> >> >>
> >> >> >> >> Good luck,
> >> >> >> >>
> >> >> >> >>    David
> >> >> >> >>
> >> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
> >> >> >> >> > In Eclipse I have a project with a package and all my source
code is in the one package.
> >> >> >> >> >
> >> >> >> >> > I would like to run JUnit test cases selectively from a separate
Java application where I run the code
> >> >> >> >> >        org.junit.runner.JUnitCore.main("example.Try.methodA");
> >> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit test
module which looks like this:
> >> >> >> >> >
> >> >> >> >> > package example;
> >> >> >> >> >
> >> >> >> >> > import org.junit.*;
> >> >> >> >> > import junit.framework.TestCase;
> >> >> >> >> >
> >> >> >> >> > public class Try extends TestCase
> >> >> >> >> > {
> >> >> >> >> >        public Try(String name) {
> >> >> >> >> >                super(name);
> >> >> >> >> >        }
> >> >> >> >> >
> >> >> >> >> >        @Before
> >> >> >> >> >        public void baseState() {
> >> >> >> >> >        }
> >> >> >> >> >
> >> >> >> >> >        @Test
> >> >> >> >> >        public void methodA() {
> >> >> >> >> >        }
> >> >> >> >> >
> >> >> >> >> > }
> >> >> >> >> >
> >> >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
> >> >> >> >> >
> >> >> >> >> > If I run Try.java as a JUnit Test I get the error
> >> >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > David
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > ------------------------------------
> >> >> >> >> >
> >> >> >> >> > Yahoo! Groups Links
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > ------------------------------------
> >> >> >> >
> >> >> >> > Yahoo! Groups Links
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > ------------------------------------
> >> >> >
> >> >> > Yahoo! Groups Links
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> > ------------------------------------
> >> >
> >> > Yahoo! Groups Links
> >> >
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>

#23097 From: "David" <davids@...>
Date: Thu Dec 2, 2010 12:03 am
Subject: Re: Running JUnit tests from a separate Java application
dljande
Send Email Send Email
 
Exceptions actually are discoverable; this line of code identifies them:

for (int i=0; i< run.getFailureCount(); i++)
	 System.out.println("Error ("+i+"): " +
run.getFailures().get(i).getException().getMessage());

David


--- In junit@yahoogroups.com, "David" <davids@...> wrote:
>
> When I put a construct like this into my code
>
> try {
>     Result run = core.run(Request.method(Try.class, actionWord));
> }
> catch (NoTestsRemainException ex) {}
>
> Java tells me
> 'Unreachable catch block for NoTestsRemainException. This exception is never
thrown from the try statement body'
>
> If I generalise the last catch to look for ANY exception the catch never
catches because the run request always returns normally.
>
> David
> --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >
> > If the test case doesn't exist, I think the failure exception should
> > be a NoTestsRemainException.  Can you check for that?
> >
> >    David Saff
> >
> > On Sun, Nov 28, 2010 at 5:51 PM, David <davids@> wrote:
> > > I had hoped I could differentiate between a failed testcase and a failure
because the testcase does not exist.
> > >
> > > David
> > >
> > > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> > >>
> > >> That's the behavior I expect.  What were you expecting to see?
> > >>
> > >>    David Saff
> > >>
> > >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
> > >> > I had hoped so but with
> > >> >
> > >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
> > >> > System.out.println("Test result: " + run.wasSuccessful() );
> > >> >
> > >> > I get run.wasSuccessful() returning false when the method fails or it
does not exist.
> > >> >
> > >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> > >> >>
> > >> >> I think that if methodA does not exist, you will get an error message.
> > >> >>  Do you see different behavior?
> > >> >>
> > >> >>    David
> > >> >>
> > >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
> > >> >> > Hi,
> > >> >> >
> > >> >> > Fantastic advice!
> > >> >> >
> > >> >> > I would also like to tell whether the methodA was actually executed
i.e. does it exist.
> > >> >> >
> > >> >> > Thanks,
> > >> >> > David
> > >> >> >
> > >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> > >> >> >>
> > >> >> >> David,
> > >> >> >>
> > >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class,
"methodA"));
> > >> >> >> 2) You can't both extend from TestCase and mark your tests with
@Test.
> > >> >> >>  Remove the extends TestCase, and more things will work.
> > >> >> >>
> > >> >> >> Good luck,
> > >> >> >>
> > >> >> >>    David
> > >> >> >>
> > >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
> > >> >> >> > In Eclipse I have a project with a package and all my source code
is in the one package.
> > >> >> >> >
> > >> >> >> > I would like to run JUnit test cases selectively from a separate
Java application where I run the code
> > >> >> >> >        org.junit.runner.JUnitCore.main("example.Try.methodA");
> > >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit test
module which looks like this:
> > >> >> >> >
> > >> >> >> > package example;
> > >> >> >> >
> > >> >> >> > import org.junit.*;
> > >> >> >> > import junit.framework.TestCase;
> > >> >> >> >
> > >> >> >> > public class Try extends TestCase
> > >> >> >> > {
> > >> >> >> >        public Try(String name) {
> > >> >> >> >                super(name);
> > >> >> >> >        }
> > >> >> >> >
> > >> >> >> >        @Before
> > >> >> >> >        public void baseState() {
> > >> >> >> >        }
> > >> >> >> >
> > >> >> >> >        @Test
> > >> >> >> >        public void methodA() {
> > >> >> >> >        }
> > >> >> >> >
> > >> >> >> > }
> > >> >> >> >
> > >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
> > >> >> >> >
> > >> >> >> > If I run Try.java as a JUnit Test I get the error
> > >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
> > >> >> >> >
> > >> >> >> >
> > >> >> >> > David
> > >> >> >> >
> > >> >> >> >
> > >> >> >> >
> > >> >> >> >
> > >> >> >> > ------------------------------------
> > >> >> >> >
> > >> >> >> > Yahoo! Groups Links
> > >> >> >> >
> > >> >> >> >
> > >> >> >> >
> > >> >> >> >
> > >> >> >>
> > >> >> >
> > >> >> >
> > >> >> >
> > >> >> >
> > >> >> > ------------------------------------
> > >> >> >
> > >> >> > Yahoo! Groups Links
> > >> >> >
> > >> >> >
> > >> >> >
> > >> >> >
> > >> >>
> > >> >
> > >> >
> > >> >
> > >> >
> > >> > ------------------------------------
> > >> >
> > >> > Yahoo! Groups Links
> > >> >
> > >> >
> > >> >
> > >> >
> > >>
> > >
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >
>

#23098 From: David Saff <david@...>
Date: Thu Dec 2, 2010 2:22 pm
Subject: Re: Re: Running JUnit tests from a separate Java application
dsaff
Send Email Send Email
 
To be clear, you've seen passing tests correctly reported, and failing
tests correctly reported, but if you pass in a non-existant test, it's
not reported at all?  What is the output you do see?  Thanks,

    David

On Wed, Dec 1, 2010 at 6:59 PM, David <davids@...> wrote:
> Hi,
>
> A glimmer of hope - exceptions from my test run are being caught.
> Refer to this code snippet:
>
> if (run.wasSuccessful())
>   System.out.println("Result: " + run.wasSuccessful());
> else if (run.getFailures().get(0).getException() instanceof
NoTestsRemainException)
> {
>   System.out.println("Method does not exist");
> }
> else {
>   for (int i=0; i< run.getFailureCount(); i++)
>        System.out.println("Error ("+i+"): " +
run.getFailures().get(i).getException().getMessage());
> }
>
> When run do not see 'Method does not exist' being reported. All output is
stemming from the last 'else'.
>
> How can I found out what exceptions are possible?
>
> David
>
> --- In junit@yahoogroups.com, David Saff <david@...> wrote:
>>
>> Sorry, could have given more information.
>>
>> Result run = core.run(Request.method(Try.class, actionWord));
>> if (run.wasSuccessful())
>>   return "success!";
>> if (run.getFailures().getException() instanceof NoTestsRemainException)
>>   return "No such method!";
>> else
>>   return "Failed for another reason!";
>>
>> On Wed, Dec 1, 2010 at 2:07 AM, David <davids@...> wrote:
>> > When I put a construct like this into my code
>> >
>> > try {
>> >    Result run = core.run(Request.method(Try.class, actionWord));
>> > }
>> > catch (NoTestsRemainException ex) {}
>> >
>> > Java tells me
>> > 'Unreachable catch block for NoTestsRemainException. This exception is
never thrown from the try statement body'
>> >
>> > If I generalise the last catch to look for ANY exception the catch never
catches because the run request always returns normally.
>> >
>> > David
>> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >>
>> >> If the test case doesn't exist, I think the failure exception should
>> >> be a NoTestsRemainException.  Can you check for that?
>> >>
>> >>    David Saff
>> >>
>> >> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@> wrote:
>> >> > I had hoped I could differentiate between a failed testcase and a
failure because the testcase does not exist.
>> >> >
>> >> > David
>> >> >
>> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >>
>> >> >> That's the behavior I expect.  What were you expecting to see?
>> >> >>
>> >> >>    David Saff
>> >> >>
>> >> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
>> >> >> > I had hoped so but with
>> >> >> >
>> >> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
>> >> >> > System.out.println("Test result: " + run.wasSuccessful() );
>> >> >> >
>> >> >> > I get run.wasSuccessful() returning false when the method fails or it
does not exist.
>> >> >> >
>> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >>
>> >> >> >> I think that if methodA does not exist, you will get an error
message.
>> >> >> >>  Do you see different behavior?
>> >> >> >>
>> >> >> >>    David
>> >> >> >>
>> >> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
>> >> >> >> > Hi,
>> >> >> >> >
>> >> >> >> > Fantastic advice!
>> >> >> >> >
>> >> >> >> > I would also like to tell whether the methodA was actually
executed i.e. does it exist.
>> >> >> >> >
>> >> >> >> > Thanks,
>> >> >> >> > David
>> >> >> >> >
>> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >> >>
>> >> >> >> >> David,
>> >> >> >> >>
>> >> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class,
"methodA"));
>> >> >> >> >> 2) You can't both extend from TestCase and mark your tests with
@Test.
>> >> >> >> >>  Remove the extends TestCase, and more things will work.
>> >> >> >> >>
>> >> >> >> >> Good luck,
>> >> >> >> >>
>> >> >> >> >>    David
>> >> >> >> >>
>> >> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
>> >> >> >> >> > In Eclipse I have a project with a package and all my source
code is in the one package.
>> >> >> >> >> >
>> >> >> >> >> > I would like to run JUnit test cases selectively from a
separate Java application where I run the code
>> >> >> >> >> >        org.junit.runner.JUnitCore.main("example.Try.methodA");
>> >> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit test
module which looks like this:
>> >> >> >> >> >
>> >> >> >> >> > package example;
>> >> >> >> >> >
>> >> >> >> >> > import org.junit.*;
>> >> >> >> >> > import junit.framework.TestCase;
>> >> >> >> >> >
>> >> >> >> >> > public class Try extends TestCase
>> >> >> >> >> > {
>> >> >> >> >> >        public Try(String name) {
>> >> >> >> >> >                super(name);
>> >> >> >> >> >        }
>> >> >> >> >> >
>> >> >> >> >> >        @Before
>> >> >> >> >> >        public void baseState() {
>> >> >> >> >> >        }
>> >> >> >> >> >
>> >> >> >> >> >        @Test
>> >> >> >> >> >        public void methodA() {
>> >> >> >> >> >        }
>> >> >> >> >> >
>> >> >> >> >> > }
>> >> >> >> >> >
>> >> >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
>> >> >> >> >> >
>> >> >> >> >> > If I run Try.java as a JUnit Test I get the error
>> >> >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > David
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > ------------------------------------
>> >> >> >> >> >
>> >> >> >> >> > Yahoo! Groups Links
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >>
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > ------------------------------------
>> >> >> >> >
>> >> >> >> > Yahoo! Groups Links
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > ------------------------------------
>> >> >> >
>> >> >> > Yahoo! Groups Links
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > ------------------------------------
>> >> >
>> >> > Yahoo! Groups Links
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>> >
>>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23099 From: Rafael Duque Estrada <rafaelduqueestrada@...>
Date: Thu Dec 2, 2010 6:21 pm
Subject: Re: Unit testing a private method??
rafaelduqueestrada@...
Send Email Send Email
 
Hi Julien,
here i use unitils and the solution was to use reflection
Search the class org.unitils.util.ReflectionUtils and use helper methods or
others utils class using Reflection solution.

2010/11/26 Rafael <rafael.naufal@...>

>
>
> Private methods are "helper" methods for other methods. If you want to test
> a private method, you should make it at least package private.
>
>
> On Fri, Nov 26, 2010 at 00:37, Karl Auer
<kauer@...<kauer%40biplane.com.au>>
> wrote:
>
> >
> >
> > On Thu, 2010-11-25 at 19:16 +0100, Julien Martin wrote:
> > > Hello,
> > > I have not used unit testing a lot but I'll have to do so in my next
> > > position as a developer. I have always wondered how to test a method
> that
> > is
> > > private. From a java point of view it is impossible. So how do you
> > > circumvent this problem and how do you make sure your private methods
> > > perform correctly?
> > > Any comment welcome.
> >
> > Google for "junit test private methods"
> >
> > Some links that I think are succinct and useful are:
> >
> > http://www.artima.com/suiterunner/private.html
> >
> > http://onjava.com/pub/a/onjava/2003/11/12/reflection.html
> >
> > At very least they are a good starting point.
> >
> > Regards, K.
> >
> > --
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Karl Auer (kauer@... <kauer%40biplane.com.au> <kauer%
> 40biplane.com.au>) +61-2-64957160
>
> > (h)
> > http://www.biplane.com.au/kauer/ +61-428-957160 (mob)
> >
> > GPG fingerprint: B386 7819 B227 2961 8301 C5A9 2EBC 754B CD97 0156
> > Old fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
>
> --
> ----------------------------------------------------------
> Rafael Naufal
> "A great pleasure in life is doing what people say you cannot do" -Walter
> Gagehot
> http://rafaelnaufal.com
> Twitter: http://twitter.com/rnaufal
> ----------------------------------------------------------
>
>
> [Non-text portions of this message have been removed]
>
>
>



--
Atenciosamente,
Rafael Ribeiro Duque Estrada Michelli


[Non-text portions of this message have been removed]

#23100 From: "David" <davids@...>
Date: Fri Dec 3, 2010 7:15 am
Subject: Re: Running JUnit tests from a separate Java application
dljande
Send Email Send Email
 
If I debug I see that I am getting an exception with detailed message
'No tests found matching Method Test Case(example.Try) from
org.junit.internal.requests.ClassRequest@36d047'

I cannot determine to what exception it corresponds.

--- In junit@yahoogroups.com, David Saff <david@...> wrote:
>
> To be clear, you've seen passing tests correctly reported, and failing
> tests correctly reported, but if you pass in a non-existant test, it's
> not reported at all?  What is the output you do see?  Thanks,
>
>    David
>
> On Wed, Dec 1, 2010 at 6:59 PM, David <davids@...> wrote:
> > Hi,
> >
> > A glimmer of hope - exceptions from my test run are being caught.
> > Refer to this code snippet:
> >
> > if (run.wasSuccessful())
> >   System.out.println("Result: " + run.wasSuccessful());
> > else if (run.getFailures().get(0).getException() instanceof
NoTestsRemainException)
> > {
> >   System.out.println("Method does not exist");
> > }
> > else {
> >   for (int i=0; i< run.getFailureCount(); i++)
> >        System.out.println("Error ("+i+"): " +
run.getFailures().get(i).getException().getMessage());
> > }
> >
> > When run do not see 'Method does not exist' being reported. All output is
stemming from the last 'else'.
> >
> > How can I found out what exceptions are possible?
> >
> > David
> >
> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >>
> >> Sorry, could have given more information.
> >>
> >> Result run = core.run(Request.method(Try.class, actionWord));
> >> if (run.wasSuccessful())
> >>   return "success!";
> >> if (run.getFailures().getException() instanceof NoTestsRemainException)
> >>   return "No such method!";
> >> else
> >>   return "Failed for another reason!";
> >>
> >> On Wed, Dec 1, 2010 at 2:07 AM, David <davids@> wrote:
> >> > When I put a construct like this into my code
> >> >
> >> > try {
> >> >    Result run = core.run(Request.method(Try.class, actionWord));
> >> > }
> >> > catch (NoTestsRemainException ex) {}
> >> >
> >> > Java tells me
> >> > 'Unreachable catch block for NoTestsRemainException. This exception is
never thrown from the try statement body'
> >> >
> >> > If I generalise the last catch to look for ANY exception the catch never
catches because the run request always returns normally.
> >> >
> >> > David
> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >>
> >> >> If the test case doesn't exist, I think the failure exception should
> >> >> be a NoTestsRemainException.  Can you check for that?
> >> >>
> >> >>    David Saff
> >> >>
> >> >> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@> wrote:
> >> >> > I had hoped I could differentiate between a failed testcase and a
failure because the testcase does not exist.
> >> >> >
> >> >> > David
> >> >> >
> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >>
> >> >> >> That's the behavior I expect.  What were you expecting to see?
> >> >> >>
> >> >> >>    David Saff
> >> >> >>
> >> >> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
> >> >> >> > I had hoped so but with
> >> >> >> >
> >> >> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
> >> >> >> > System.out.println("Test result: " + run.wasSuccessful() );
> >> >> >> >
> >> >> >> > I get run.wasSuccessful() returning false when the method fails or
it does not exist.
> >> >> >> >
> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >> >>
> >> >> >> >> I think that if methodA does not exist, you will get an error
message.
> >> >> >> >>  Do you see different behavior?
> >> >> >> >>
> >> >> >> >>    David
> >> >> >> >>
> >> >> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
> >> >> >> >> > Hi,
> >> >> >> >> >
> >> >> >> >> > Fantastic advice!
> >> >> >> >> >
> >> >> >> >> > I would also like to tell whether the methodA was actually
executed i.e. does it exist.
> >> >> >> >> >
> >> >> >> >> > Thanks,
> >> >> >> >> > David
> >> >> >> >> >
> >> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >> >> >>
> >> >> >> >> >> David,
> >> >> >> >> >>
> >> >> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class,
"methodA"));
> >> >> >> >> >> 2) You can't both extend from TestCase and mark your tests with
@Test.
> >> >> >> >> >>  Remove the extends TestCase, and more things will work.
> >> >> >> >> >>
> >> >> >> >> >> Good luck,
> >> >> >> >> >>
> >> >> >> >> >>    David
> >> >> >> >> >>
> >> >> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
> >> >> >> >> >> > In Eclipse I have a project with a package and all my source
code is in the one package.
> >> >> >> >> >> >
> >> >> >> >> >> > I would like to run JUnit test cases selectively from a
separate Java application where I run the code
> >> >> >> >> >> >      
 org.junit.runner.JUnitCore.main("example.Try.methodA");
> >> >> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit test
module which looks like this:
> >> >> >> >> >> >
> >> >> >> >> >> > package example;
> >> >> >> >> >> >
> >> >> >> >> >> > import org.junit.*;
> >> >> >> >> >> > import junit.framework.TestCase;
> >> >> >> >> >> >
> >> >> >> >> >> > public class Try extends TestCase
> >> >> >> >> >> > {
> >> >> >> >> >> >        public Try(String name) {
> >> >> >> >> >> >                super(name);
> >> >> >> >> >> >        }
> >> >> >> >> >> >
> >> >> >> >> >> >        @Before
> >> >> >> >> >> >        public void baseState() {
> >> >> >> >> >> >        }
> >> >> >> >> >> >
> >> >> >> >> >> >        @Test
> >> >> >> >> >> >        public void methodA() {
> >> >> >> >> >> >        }
> >> >> >> >> >> >
> >> >> >> >> >> > }
> >> >> >> >> >> >
> >> >> >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
> >> >> >> >> >> >
> >> >> >> >> >> > If I run Try.java as a JUnit Test I get the error
> >> >> >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > David
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > ------------------------------------
> >> >> >> >> >> >
> >> >> >> >> >> > Yahoo! Groups Links
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >>
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > ------------------------------------
> >> >> >> >> >
> >> >> >> >> > Yahoo! Groups Links
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > ------------------------------------
> >> >> >> >
> >> >> >> > Yahoo! Groups Links
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > ------------------------------------
> >> >> >
> >> >> > Yahoo! Groups Links
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> > ------------------------------------
> >> >
> >> > Yahoo! Groups Links
> >> >
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>

#23101 From: Bill Venners <bill@...>
Date: Fri Dec 3, 2010 7:40 am
Subject: Re: Unit testing a private method??
billvenners
Send Email Send Email
 
Hi Karl,

I had forgotten I even wrote that article. It is quite verbose what I ended
up needing to do to test a private method in Java. I included a trait in
ScalaTest, which is the descendant of SuiteRunner, to test private methods
with very minimal code:

http://scalatest.org/scaladoc/doc-1.1/org/scalatest/PrivateMethodTester.html

This is heavily integrated with JUnit, a JUnit extension to a great extent.
And it can be used to test private Java methods. But you need to use Scala
as the testing language.

Bill

On Thu, Nov 25, 2010 at 6:37 PM, Karl Auer <kauer@...> wrote:

>
>
> On Thu, 2010-11-25 at 19:16 +0100, Julien Martin wrote:
> > Hello,
> > I have not used unit testing a lot but I'll have to do so in my next
> > position as a developer. I have always wondered how to test a method that
> is
> > private. From a java point of view it is impossible. So how do you
> > circumvent this problem and how do you make sure your private methods
> > perform correctly?
> > Any comment welcome.
>
> Google for "junit test private methods"
>
> Some links that I think are succinct and useful are:
>
> http://www.artima.com/suiterunner/private.html
>
> http://onjava.com/pub/a/onjava/2003/11/12/reflection.html
>
> At very least they are a good starting point.
>
> Regards, K.
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Karl Auer (kauer@... <kauer%40biplane.com.au>) +61-2-64957160
> (h)
> http://www.biplane.com.au/kauer/ +61-428-957160 (mob)
>
> GPG fingerprint: B386 7819 B227 2961 8301 C5A9 2EBC 754B CD97 0156
> Old fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF
>
>
> [Non-text portions of this message have been removed]
>
>
>



--
Bill Venners
Artima, Inc.
http://www.artima.com


[Non-text portions of this message have been removed]

#23102 From: David Saff <david@...>
Date: Fri Dec 3, 2010 2:53 pm
Subject: Re: Re: Running JUnit tests from a separate Java application
dsaff
Send Email Send Email
 
Can you use your code above to print
run.getFailures().get(i).getException().getClass().getName()?

    David Saff

On Fri, Dec 3, 2010 at 2:15 AM, David <davids@...> wrote:
> If I debug I see that I am getting an exception with detailed message
> 'No tests found matching Method Test Case(example.Try) from
org.junit.internal.requests.ClassRequest@36d047'
>
> I cannot determine to what exception it corresponds.
>
> --- In junit@yahoogroups.com, David Saff <david@...> wrote:
>>
>> To be clear, you've seen passing tests correctly reported, and failing
>> tests correctly reported, but if you pass in a non-existant test, it's
>> not reported at all?  What is the output you do see?  Thanks,
>>
>>    David
>>
>> On Wed, Dec 1, 2010 at 6:59 PM, David <davids@...> wrote:
>> > Hi,
>> >
>> > A glimmer of hope - exceptions from my test run are being caught.
>> > Refer to this code snippet:
>> >
>> > if (run.wasSuccessful())
>> >   System.out.println("Result: " + run.wasSuccessful());
>> > else if (run.getFailures().get(0).getException() instanceof
NoTestsRemainException)
>> > {
>> >   System.out.println("Method does not exist");
>> > }
>> > else {
>> >   for (int i=0; i< run.getFailureCount(); i++)
>> >        System.out.println("Error ("+i+"): " +
run.getFailures().get(i).getException().getMessage());
>> > }
>> >
>> > When run do not see 'Method does not exist' being reported. All output is
stemming from the last 'else'.
>> >
>> > How can I found out what exceptions are possible?
>> >
>> > David
>> >
>> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >>
>> >> Sorry, could have given more information.
>> >>
>> >> Result run = core.run(Request.method(Try.class, actionWord));
>> >> if (run.wasSuccessful())
>> >>   return "success!";
>> >> if (run.getFailures().getException() instanceof NoTestsRemainException)
>> >>   return "No such method!";
>> >> else
>> >>   return "Failed for another reason!";
>> >>
>> >> On Wed, Dec 1, 2010 at 2:07 AM, David <davids@> wrote:
>> >> > When I put a construct like this into my code
>> >> >
>> >> > try {
>> >> >    Result run = core.run(Request.method(Try.class, actionWord));
>> >> > }
>> >> > catch (NoTestsRemainException ex) {}
>> >> >
>> >> > Java tells me
>> >> > 'Unreachable catch block for NoTestsRemainException. This exception is
never thrown from the try statement body'
>> >> >
>> >> > If I generalise the last catch to look for ANY exception the catch never
catches because the run request always returns normally.
>> >> >
>> >> > David
>> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >>
>> >> >> If the test case doesn't exist, I think the failure exception should
>> >> >> be a NoTestsRemainException.  Can you check for that?
>> >> >>
>> >> >>    David Saff
>> >> >>
>> >> >> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@> wrote:
>> >> >> > I had hoped I could differentiate between a failed testcase and a
failure because the testcase does not exist.
>> >> >> >
>> >> >> > David
>> >> >> >
>> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >>
>> >> >> >> That's the behavior I expect.  What were you expecting to see?
>> >> >> >>
>> >> >> >>    David Saff
>> >> >> >>
>> >> >> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
>> >> >> >> > I had hoped so but with
>> >> >> >> >
>> >> >> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
>> >> >> >> > System.out.println("Test result: " + run.wasSuccessful() );
>> >> >> >> >
>> >> >> >> > I get run.wasSuccessful() returning false when the method fails or
it does not exist.
>> >> >> >> >
>> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >> >>
>> >> >> >> >> I think that if methodA does not exist, you will get an error
message.
>> >> >> >> >>  Do you see different behavior?
>> >> >> >> >>
>> >> >> >> >>    David
>> >> >> >> >>
>> >> >> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
>> >> >> >> >> > Hi,
>> >> >> >> >> >
>> >> >> >> >> > Fantastic advice!
>> >> >> >> >> >
>> >> >> >> >> > I would also like to tell whether the methodA was actually
executed i.e. does it exist.
>> >> >> >> >> >
>> >> >> >> >> > Thanks,
>> >> >> >> >> > David
>> >> >> >> >> >
>> >> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >> >> >>
>> >> >> >> >> >> David,
>> >> >> >> >> >>
>> >> >> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class,
"methodA"));
>> >> >> >> >> >> 2) You can't both extend from TestCase and mark your tests
with @Test.
>> >> >> >> >> >>  Remove the extends TestCase, and more things will work.
>> >> >> >> >> >>
>> >> >> >> >> >> Good luck,
>> >> >> >> >> >>
>> >> >> >> >> >>    David
>> >> >> >> >> >>
>> >> >> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
>> >> >> >> >> >> > In Eclipse I have a project with a package and all my source
code is in the one package.
>> >> >> >> >> >> >
>> >> >> >> >> >> > I would like to run JUnit test cases selectively from a
separate Java application where I run the code
>> >> >> >> >> >> >      
 org.junit.runner.JUnitCore.main("example.Try.methodA");
>> >> >> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit
test module which looks like this:
>> >> >> >> >> >> >
>> >> >> >> >> >> > package example;
>> >> >> >> >> >> >
>> >> >> >> >> >> > import org.junit.*;
>> >> >> >> >> >> > import junit.framework.TestCase;
>> >> >> >> >> >> >
>> >> >> >> >> >> > public class Try extends TestCase
>> >> >> >> >> >> > {
>> >> >> >> >> >> >        public Try(String name) {
>> >> >> >> >> >> >                super(name);
>> >> >> >> >> >> >        }
>> >> >> >> >> >> >
>> >> >> >> >> >> >        @Before
>> >> >> >> >> >> >        public void baseState() {
>> >> >> >> >> >> >        }
>> >> >> >> >> >> >
>> >> >> >> >> >> >        @Test
>> >> >> >> >> >> >        public void methodA() {
>> >> >> >> >> >> >        }
>> >> >> >> >> >> >
>> >> >> >> >> >> > }
>> >> >> >> >> >> >
>> >> >> >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
>> >> >> >> >> >> >
>> >> >> >> >> >> > If I run Try.java as a JUnit Test I get the error
>> >> >> >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > David
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > ------------------------------------
>> >> >> >> >> >> >
>> >> >> >> >> >> > Yahoo! Groups Links
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >>
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > ------------------------------------
>> >> >> >> >> >
>> >> >> >> >> > Yahoo! Groups Links
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >>
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > ------------------------------------
>> >> >> >> >
>> >> >> >> > Yahoo! Groups Links
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > ------------------------------------
>> >> >> >
>> >> >> > Yahoo! Groups Links
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > ------------------------------------
>> >> >
>> >> > Yahoo! Groups Links
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>> >
>>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23103 From: Karl Auer <kauer@...>
Date: Fri Dec 3, 2010 9:41 am
Subject: Re: Unit testing a private method??
kristoferamp...
Send Email Send Email
 
On Thu, 2010-12-02 at 23:40 -0800, Bill Venners wrote:
> I had forgotten I even wrote that article. It is quite verbose what I ended
> up needing to do to test a private method in Java.

I personally think that every method needs testing; it's a basic part of
"divide and conquer". It seems bizarre to me that people seriously
believe only public API methods need testing. Smells a bit
ideological...

To use an analogy, if I'm building (say) a table, I will measure each
component as I make it, to make sure it is the right size and shape.

Regards, K.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer@...)                   +61-2-64957160 (h)
http://www.biplane.com.au/kauer/                   +61-428-957160 (mob)

GPG fingerprint: B386 7819 B227 2961 8301 C5A9 2EBC 754B CD97 0156
Old fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF


[Non-text portions of this message have been removed]

#23104 From: Cédric Beust ♔ <cedric@...>
Date: Fri Dec 3, 2010 10:56 pm
Subject: Re: Unit testing a private method??
cbeust
Send Email Send Email
 
On Fri, Dec 3, 2010 at 1:41 AM, Karl Auer <kauer@...> wrote:

> On Thu, 2010-12-02 at 23:40 -0800, Bill Venners wrote:
> > I had forgotten I even wrote that article. It is quite verbose what I
> ended
> > up needing to do to test a private method in Java.
>
> I personally think that every method needs testing; it's a basic part of
> "divide and conquer". It seems bizarre to me that people seriously
> believe only public API methods need testing. Smells a bit
> ideological...
>

Agreed. More generally, I think that any code that can potentially break
needs to be tested.

Saying that private methods need to be tested through public API's only is
the same as saying that you don't need unit testing since you are already
doing integration testing.

--
Cédric


[Non-text portions of this message have been removed]

#23105 From: "David" <davids@...>
Date: Fri Dec 3, 2010 11:06 pm
Subject: Re: Running JUnit tests from a separate Java application
dljande
Send Email Send Email
 
And I get 'java.lang.Exception' which is not very exciting

--- In junit@yahoogroups.com, David Saff <david@...> wrote:
>
> Can you use your code above to print
> run.getFailures().get(i).getException().getClass().getName()?
>
>    David Saff
>
> On Fri, Dec 3, 2010 at 2:15 AM, David <davids@...> wrote:
> > If I debug I see that I am getting an exception with detailed message
> > 'No tests found matching Method Test Case(example.Try) from
org.junit.internal.requests.ClassRequest@36d047'
> >
> > I cannot determine to what exception it corresponds.
> >
> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >>
> >> To be clear, you've seen passing tests correctly reported, and failing
> >> tests correctly reported, but if you pass in a non-existant test, it's
> >> not reported at all?  What is the output you do see?  Thanks,
> >>
> >>    David
> >>
> >> On Wed, Dec 1, 2010 at 6:59 PM, David <davids@> wrote:
> >> > Hi,
> >> >
> >> > A glimmer of hope - exceptions from my test run are being caught.
> >> > Refer to this code snippet:
> >> >
> >> > if (run.wasSuccessful())
> >> >   System.out.println("Result: " + run.wasSuccessful());
> >> > else if (run.getFailures().get(0).getException() instanceof
NoTestsRemainException)
> >> > {
> >> >   System.out.println("Method does not exist");
> >> > }
> >> > else {
> >> >   for (int i=0; i< run.getFailureCount(); i++)
> >> >        System.out.println("Error ("+i+"): " +
run.getFailures().get(i).getException().getMessage());
> >> > }
> >> >
> >> > When run do not see 'Method does not exist' being reported. All output is
stemming from the last 'else'.
> >> >
> >> > How can I found out what exceptions are possible?
> >> >
> >> > David
> >> >
> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >>
> >> >> Sorry, could have given more information.
> >> >>
> >> >> Result run = core.run(Request.method(Try.class, actionWord));
> >> >> if (run.wasSuccessful())
> >> >>   return "success!";
> >> >> if (run.getFailures().getException() instanceof NoTestsRemainException)
> >> >>   return "No such method!";
> >> >> else
> >> >>   return "Failed for another reason!";
> >> >>
> >> >> On Wed, Dec 1, 2010 at 2:07 AM, David <davids@> wrote:
> >> >> > When I put a construct like this into my code
> >> >> >
> >> >> > try {
> >> >> >    Result run = core.run(Request.method(Try.class, actionWord));
> >> >> > }
> >> >> > catch (NoTestsRemainException ex) {}
> >> >> >
> >> >> > Java tells me
> >> >> > 'Unreachable catch block for NoTestsRemainException. This exception is
never thrown from the try statement body'
> >> >> >
> >> >> > If I generalise the last catch to look for ANY exception the catch
never catches because the run request always returns normally.
> >> >> >
> >> >> > David
> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >>
> >> >> >> If the test case doesn't exist, I think the failure exception should
> >> >> >> be a NoTestsRemainException.  Can you check for that?
> >> >> >>
> >> >> >>    David Saff
> >> >> >>
> >> >> >> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@> wrote:
> >> >> >> > I had hoped I could differentiate between a failed testcase and a
failure because the testcase does not exist.
> >> >> >> >
> >> >> >> > David
> >> >> >> >
> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >> >>
> >> >> >> >> That's the behavior I expect.  What were you expecting to see?
> >> >> >> >>
> >> >> >> >>    David Saff
> >> >> >> >>
> >> >> >> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
> >> >> >> >> > I had hoped so but with
> >> >> >> >> >
> >> >> >> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
> >> >> >> >> > System.out.println("Test result: " + run.wasSuccessful() );
> >> >> >> >> >
> >> >> >> >> > I get run.wasSuccessful() returning false when the method fails
or it does not exist.
> >> >> >> >> >
> >> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >> >> >>
> >> >> >> >> >> I think that if methodA does not exist, you will get an error
message.
> >> >> >> >> >>  Do you see different behavior?
> >> >> >> >> >>
> >> >> >> >> >>    David
> >> >> >> >> >>
> >> >> >> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
> >> >> >> >> >> > Hi,
> >> >> >> >> >> >
> >> >> >> >> >> > Fantastic advice!
> >> >> >> >> >> >
> >> >> >> >> >> > I would also like to tell whether the methodA was actually
executed i.e. does it exist.
> >> >> >> >> >> >
> >> >> >> >> >> > Thanks,
> >> >> >> >> >> > David
> >> >> >> >> >> >
> >> >> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
> >> >> >> >> >> >>
> >> >> >> >> >> >> David,
> >> >> >> >> >> >>
> >> >> >> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class,
"methodA"));
> >> >> >> >> >> >> 2) You can't both extend from TestCase and mark your tests
with @Test.
> >> >> >> >> >> >>  Remove the extends TestCase, and more things will work.
> >> >> >> >> >> >>
> >> >> >> >> >> >> Good luck,
> >> >> >> >> >> >>
> >> >> >> >> >> >>    David
> >> >> >> >> >> >>
> >> >> >> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
> >> >> >> >> >> >> > In Eclipse I have a project with a package and all my
source code is in the one package.
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > I would like to run JUnit test cases selectively from a
separate Java application where I run the code
> >> >> >> >> >> >> >      
 org.junit.runner.JUnitCore.main("example.Try.methodA");
> >> >> >> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit
test module which looks like this:
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > package example;
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > import org.junit.*;
> >> >> >> >> >> >> > import junit.framework.TestCase;
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > public class Try extends TestCase
> >> >> >> >> >> >> > {
> >> >> >> >> >> >> >        public Try(String name) {
> >> >> >> >> >> >> >                super(name);
> >> >> >> >> >> >> >        }
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >        @Before
> >> >> >> >> >> >> >        public void baseState() {
> >> >> >> >> >> >> >        }
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >        @Test
> >> >> >> >> >> >> >        public void methodA() {
> >> >> >> >> >> >> >        }
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > }
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > If I run Try.java as a JUnit Test I get the error
> >> >> >> >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > David
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > ------------------------------------
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > Yahoo! Groups Links
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >>
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > ------------------------------------
> >> >> >> >> >> >
> >> >> >> >> >> > Yahoo! Groups Links
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >>
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > ------------------------------------
> >> >> >> >> >
> >> >> >> >> > Yahoo! Groups Links
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > ------------------------------------
> >> >> >> >
> >> >> >> > Yahoo! Groups Links
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > ------------------------------------
> >> >> >
> >> >> > Yahoo! Groups Links
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> > ------------------------------------
> >> >
> >> > Yahoo! Groups Links
> >> >
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>

#23106 From: Charlie Poole <charlie@...>
Date: Fri Dec 3, 2010 11:52 pm
Subject: Re: Unit testing a private method??
cpoole98370
Send Email Send Email
 
I agree with both of you. Except...

I haven't heard anybody but raw beginners claim that private methods
don't need testing.

You are ignoring the most frequently stated issue with the testing of
private methods. In the wild, when folks "need" to test a private method,
it most usually means that they aren't looking carefully enough at the
design of the class they are testing. I'd say that 9 times out of 10, the
average developer should split the class rather than reach inside to
test a private method.

Charlie


2010/12/3 Cédric Beust ♔ <cedric@...>:
> On Fri, Dec 3, 2010 at 1:41 AM, Karl Auer <kauer@...> wrote:
>
>> On Thu, 2010-12-02 at 23:40 -0800, Bill Venners wrote:
>> > I had forgotten I even wrote that article. It is quite verbose what I
>> ended
>> > up needing to do to test a private method in Java.
>>
>> I personally think that every method needs testing; it's a basic part of
>> "divide and conquer". It seems bizarre to me that people seriously
>> believe only public API methods need testing. Smells a bit
>> ideological...
>>
>
> Agreed. More generally, I think that any code that can potentially break
> needs to be tested.
>
> Saying that private methods need to be tested through public API's only is
> the same as saying that you don't need unit testing since you are already
> doing integration testing.
>
> --
> Cédric
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23107 From: "mphilipp1982" <mphilipp82@...>
Date: Sat Dec 4, 2010 2:58 pm
Subject: Re: Unit testing a private method??
mphilipp1982
Send Email Send Email
 
I absolutely agree with Charlie. Lasse Koskela recently blogged about this issue
here:

http://lassekoskela.com/thoughts/24/test-everything-but-not-private-methods/

Marc

--- In junit@yahoogroups.com, Charlie Poole <charlie@...> wrote:
>
> I agree with both of you. Except...
>
> I haven't heard anybody but raw beginners claim that private methods
> don't need testing.
>
> You are ignoring the most frequently stated issue with the testing of
> private methods. In the wild, when folks "need" to test a private method,
> it most usually means that they aren't looking carefully enough at the
> design of the class they are testing. I'd say that 9 times out of 10, the
> average developer should split the class rather than reach inside to
> test a private method.
>
> Charlie
>
>
> 2010/12/3 CĂ©dric Beust â™" <cedric@...>:
> > On Fri, Dec 3, 2010 at 1:41 AM, Karl Auer <kauer@...> wrote:
> >
> >> On Thu, 2010-12-02 at 23:40 -0800, Bill Venners wrote:
> >> > I had forgotten I even wrote that article. It is quite verbose what I
> >> ended
> >> > up needing to do to test a private method in Java.
> >>
> >> I personally think that every method needs testing; it's a basic part of
> >> "divide and conquer". It seems bizarre to me that people seriously
> >> believe only public API methods need testing. Smells a bit
> >> ideological...
> >>
> >
> > Agreed. More generally, I think that any code that can potentially break
> > needs to be tested.
> >
> > Saying that private methods need to be tested through public API's only is
> > the same as saying that you don't need unit testing since you are already
> > doing integration testing.
> >
> > --
> > Cédric
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>

#23108 From: Cédric Beust ♔ <cedric@...>
Date: Sat Dec 4, 2010 9:27 pm
Subject: Re: Re: Unit testing a private method??
cbeust
Send Email Send Email
 
On Sat, Dec 4, 2010 at 6:58 AM, mphilipp1982 <mphilipp82@...> wrote:

>
>
> I absolutely agree with Charlie. Lasse Koskela recently blogged about this
> issue here:
>
>
> http://lassekoskela.com/thoughts/24/test-everything-but-not-private-methods/


Sorry, but Lasse seems to disagree with both Charlie and myself. He's saying
that you should never test private methods directly, only indirectly through
public methods.

I find this angle puzzling, since as I said above, if you follow this
reasoning, since all your code is already being tested indirectly by
functional testing, why do unit testing at all?

The main reason why I sometimes want to test private methods is not fear, as
Lasse claims, but simply the fact that this functionality can break.
Therefore, it deserves a test of its own.

There are two extreme ways to test private methods, both bad:

    - Use reflection + setAccessible. Very fragile, avoid.
    - Use public methods that call this private method. Not good enough.

I tend to favor the middle ground approach, which is to relax the scope of
the method so that tests can see it. Making it package protected and putting
a comment ("/* for testing */") usually works, but if it doesn't, I don't
have a problem with making this method public for testing.

--
Cédric


[Non-text portions of this message have been removed]

#23109 From: Dale Emery <dale@...>
Date: Sat Dec 4, 2010 10:10 pm
Subject: Re: Re: Unit testing a private method??
dhemery...
Send Email Send Email
 
Hi Cedric,

Sorry, but Lasse seems to disagree with both Charlie and myself. He's
> saying that you should never test private methods directly, only indirectly
> through public methods.
>

Note the end of the article, where Lasse recommends this: Move the private
method to a new class where it is public, then test it directly.

Dale

--
Dale Emery
Consultant to software teams and leaders
Web: http://dhemery.com


[Non-text portions of this message have been removed]

#23110 From: Mike Forsberg <bigmike.f@...>
Date: Sun Dec 5, 2010 12:17 am
Subject: Re: Re: Unit testing a private method??
bigmike_f
Send Email Send Email
 
It is scary to hear of code that may have broken functionality in a private
method while the caller methods do not reveal the classes brokenness.  If a
private method were performing incorrectly, yet all the functionality
exposed at the protected level and above works correctly, one would have to
ask, "What is the man behind the curtain really doing?".

In a slightly different vain, if a developer were writing tests as sign
posts to signify that an error has occurred, shouldn't that sign post be
viewable at a higher then private level.

Consider a public API that is tested thoroughly and is functionally
correct.  Yet, there is a private method that still has a functional error.
This should be a signal that the extra incorrect functionality is
unreachable or unnecessary.

In regards to... why do unit testing at all if everything is tested through
functional testing.

Personally, if I could get every scenario to run at the
integration/functional level within the time I can run my unit tests, I'd
only write unit tests to track down why the higher level tests are failing.
In this amazing world, a unit test would only be needed to track down a bug
since my brain is not big enough to hold the whole system in it's mind.
However, once the bug is fixed, the unit test can grow stale.  As I'd be
assured that every possible scenario is tested.

For me, the reality is that customers don't care that
- every method performs correctly
- a given method supplies incorrect answers in certain conditions
They only care that the result they need is correct when they need it.

Since it is the customer that is paying me, I'd rather only care what they
care about.

Making a rough calculation that
- The price of enough machines to run every integration/functional test
within a reasonable amount of time is too much money.
- I don't write perfect code, and I'd most likely need targeted tests that
can run parts of the system in case there is a bug.
- Since I know what I'm changing when I change it, I can keep a
corresponding set of tests up-to-date with the code changes.
It behooves me to keep some unit tests laying around.

Then, since they are laying around and are up-to-date, why not run all the
ones above the code that I'm changing.  And thus I keep a set of unit tests
for each class.  Should I run all the unit test?  Nope, if their code was
not touched, then they should still pass.  If it is the case that the tests
might fail, then I might have bad architecture or class design.

My two cents,

Big Mike


2010/12/4 Cédric Beust ♔ <cedric@...>

>
>
> On Sat, Dec 4, 2010 at 6:58 AM, mphilipp1982
<mphilipp82@...<mphilipp82%40gmail.com>>
> wrote:
>
> >
> >
> > I absolutely agree with Charlie. Lasse Koskela recently blogged about
> this
> > issue here:
> >
> >
> >
> http://lassekoskela.com/thoughts/24/test-everything-but-not-private-methods/
>
> Sorry, but Lasse seems to disagree with both Charlie and myself. He's
> saying
> that you should never test private methods directly, only indirectly
> through
> public methods.
>
> I find this angle puzzling, since as I said above, if you follow this
> reasoning, since all your code is already being tested indirectly by
> functional testing, why do unit testing at all?
>
> The main reason why I sometimes want to test private methods is not fear,
> as
> Lasse claims, but simply the fact that this functionality can break.
> Therefore, it deserves a test of its own.
>
> There are two extreme ways to test private methods, both bad:
>
> - Use reflection + setAccessible. Very fragile, avoid.
> - Use public methods that call this private method. Not good enough.
>
> I tend to favor the middle ground approach, which is to relax the scope of
> the method so that tests can see it. Making it package protected and
> putting
> a comment ("/* for testing */") usually works, but if it doesn't, I don't
> have a problem with making this method public for testing.
>
> --
> Cédric
>
>
> [Non-text portions of this message have been removed]
>
>
>


[Non-text portions of this message have been removed]

#23111 From: Cédric Beust ♔ <cedric@...>
Date: Sun Dec 5, 2010 5:41 am
Subject: Re: Re: Unit testing a private method??
cbeust
Send Email Send Email
 
On Sat, Dec 4, 2010 at 4:17 PM, Mike Forsberg <bigmike.f@...> wrote:

> For me, the reality is that customers don't care that
> - every method performs correctly
> - a given method supplies incorrect answers in certain conditions
> They only care that the result they need is correct when they need it.
>
> Since it is the customer that is paying me, I'd rather only care what they
> care about.
>

That's a truth that too many engineers tend to forget about, and this is why
in the grander scheme of things, functional tests are so much more important
than unit tests.

Here is the reality: unit tests are a comfort *for the developer*.
Functional tests are a necessity *for the user*.

Functional tests allow you to make sure that a functionality that you are
shipping and that will be used by your consumers will work as expected.

Unit tests give you no such guarantee. 100% unit tests might be passing and
still, your application might be completely broken.

This is the reason why if I'm pressed with time and I have to choose between
writing a unit test or a functional test, I will choose to write a
functional test 100% of the time. Then later, if I find some extra time,
I'll try to write a few unit tests that will allow me to converge toward
problems faster. Because that's all unit tests enable: faster pinpointing of
a problem. If 100% of your tests are functional, you will still find the
problem but it might take you a little longer. Not a big deal.

It's unfortunate that unit tests have become such a high focus of attention
lately (and another reason why TDD makes me uncomfortable). High emphasis on
unit tests and on TDD is engineers trying to make their work easier. It's a
laudable goal, but it should never come at the expense of the person whom
you are working for: the customer.

And the only tests that really matter to the customer are functional tests.

--
Cédric


[Non-text portions of this message have been removed]

#23112 From: David Saff <david@...>
Date: Sun Dec 5, 2010 8:13 pm
Subject: Re: Re: Unit testing a private method??
dsaff
Send Email Send Email
 
2010/12/5 Cédric Beust ♔ <cedric@...>:
> On Sat, Dec 4, 2010 at 4:17 PM, Mike Forsberg <bigmike.f@...> wrote:
>
>> For me, the reality is that customers don't care that
>> - every method performs correctly
>> - a given method supplies incorrect answers in certain conditions
>> They only care that the result they need is correct when they need it.
>>
>> Since it is the customer that is paying me, I'd rather only care what they
>> care about.
>>
>
> That's a truth that too many engineers tend to forget about, and this is why
> in the grander scheme of things, functional tests are so much more important
> than unit tests.
>
> Here is the reality: unit tests are a comfort *for the developer*.
> Functional tests are a necessity *for the user*.
>
> Functional tests allow you to make sure that a functionality that you are
> shipping and that will be used by your consumers will work as expected.
>
> Unit tests give you no such guarantee. 100% unit tests might be passing and
> still, your application might be completely broken.
>
> This is the reason why if I'm pressed with time and I have to choose between
> writing a unit test or a functional test, I will choose to write a
> functional test 100% of the time. Then later, if I find some extra time,
> I'll try to write a few unit tests that will allow me to converge toward
> problems faster. Because that's all unit tests enable: faster pinpointing of
> a problem. If 100% of your tests are functional, you will still find the
> problem but it might take you a little longer. Not a big deal.
>
> It's unfortunate that unit tests have become such a high focus of attention
> lately (and another reason why TDD makes me uncomfortable). High emphasis on
> unit tests and on TDD is engineers trying to make their work easier. It's a
> laudable goal, but it should never come at the expense of the person whom
> you are working for: the customer.
>
> And the only tests that really matter to the customer are functional tests.

I tend to try many different approaches to software development, since
I plan to be doing it for decades to come, and don't want to get stuck
in a local maximum.  I pay special attention to techniques that people
I trust say good things about, but I haven't tried, or haven't been
successful with.  At this point, I find that test-driven development,
with the discipline of changing my design when writing the unit tests
hurts, produces the highest-quality software at the highest speed.  I
expect I'll continue to try variations on the formula and others.

This isn't the first time that Cedric and I have discussed this
particular point, so you can probably refer to previous mails on this
list if I don't expand every thought here.

- Most engineers and craftsmen consider it professional to have
structures they use during design and construction that make their job
easier, but might not obviously contribute to final quality from an
outsider's perspective.  Home contractors might use scaffolding,
temporary lighting, pencil marks on the walls, clamps.  As a customer,
I do not begrudge these tools, saying "without that temporary
lighting, you'll probably make more mistakes, and it might take you
longer to find them and fix them, but eventually it will get done."

- On being "pressed for time": I assume that a very experienced auto
engineer can make a professional decision, when pressed for time,
about whether to thoroughly test the airbags in my car using crash
test dummies, or using a more isolated lab test.  I also really hope
that if both are valuable, a very professional auto engineer makes
sure there's time in the schedule for both, and doesn't spend a lot of
time arguing with peers about which to drop in order to shorten the
schedule.

- No tests matter to the customer.  Working software matters to the
customer.  What produces working software is a matter best
investigated through history and experience.

Thanks,

    David

>
> --
> Cédric
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23113 From: David Saff <david@...>
Date: Sun Dec 5, 2010 8:15 pm
Subject: Re: Re: Running JUnit tests from a separate Java application
dsaff
Send Email Send Email
 
Hmm.  Sounds like you can probably get what you need by checking the
exception message, but please file a feature request for a more
reliable notification.  Thanks!

    David Saff

On Fri, Dec 3, 2010 at 6:06 PM, David <davids@...> wrote:
> And I get 'java.lang.Exception' which is not very exciting
>
> --- In junit@yahoogroups.com, David Saff <david@...> wrote:
>>
>> Can you use your code above to print
>> run.getFailures().get(i).getException().getClass().getName()?
>>
>>    David Saff
>>
>> On Fri, Dec 3, 2010 at 2:15 AM, David <davids@...> wrote:
>> > If I debug I see that I am getting an exception with detailed message
>> > 'No tests found matching Method Test Case(example.Try) from
org.junit.internal.requests.ClassRequest@36d047'
>> >
>> > I cannot determine to what exception it corresponds.
>> >
>> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >>
>> >> To be clear, you've seen passing tests correctly reported, and failing
>> >> tests correctly reported, but if you pass in a non-existant test, it's
>> >> not reported at all?  What is the output you do see?  Thanks,
>> >>
>> >>    David
>> >>
>> >> On Wed, Dec 1, 2010 at 6:59 PM, David <davids@> wrote:
>> >> > Hi,
>> >> >
>> >> > A glimmer of hope - exceptions from my test run are being caught.
>> >> > Refer to this code snippet:
>> >> >
>> >> > if (run.wasSuccessful())
>> >> >   System.out.println("Result: " + run.wasSuccessful());
>> >> > else if (run.getFailures().get(0).getException() instanceof
NoTestsRemainException)
>> >> > {
>> >> >   System.out.println("Method does not exist");
>> >> > }
>> >> > else {
>> >> >   for (int i=0; i< run.getFailureCount(); i++)
>> >> >        System.out.println("Error ("+i+"): " +
run.getFailures().get(i).getException().getMessage());
>> >> > }
>> >> >
>> >> > When run do not see 'Method does not exist' being reported. All output
is stemming from the last 'else'.
>> >> >
>> >> > How can I found out what exceptions are possible?
>> >> >
>> >> > David
>> >> >
>> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >>
>> >> >> Sorry, could have given more information.
>> >> >>
>> >> >> Result run = core.run(Request.method(Try.class, actionWord));
>> >> >> if (run.wasSuccessful())
>> >> >>   return "success!";
>> >> >> if (run.getFailures().getException() instanceof NoTestsRemainException)
>> >> >>   return "No such method!";
>> >> >> else
>> >> >>   return "Failed for another reason!";
>> >> >>
>> >> >> On Wed, Dec 1, 2010 at 2:07 AM, David <davids@> wrote:
>> >> >> > When I put a construct like this into my code
>> >> >> >
>> >> >> > try {
>> >> >> >    Result run = core.run(Request.method(Try.class, actionWord));
>> >> >> > }
>> >> >> > catch (NoTestsRemainException ex) {}
>> >> >> >
>> >> >> > Java tells me
>> >> >> > 'Unreachable catch block for NoTestsRemainException. This exception
is never thrown from the try statement body'
>> >> >> >
>> >> >> > If I generalise the last catch to look for ANY exception the catch
never catches because the run request always returns normally.
>> >> >> >
>> >> >> > David
>> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >>
>> >> >> >> If the test case doesn't exist, I think the failure exception should
>> >> >> >> be a NoTestsRemainException.  Can you check for that?
>> >> >> >>
>> >> >> >>    David Saff
>> >> >> >>
>> >> >> >> On Sun, Nov 28, 2010 at 5:51 PM, David <davids@> wrote:
>> >> >> >> > I had hoped I could differentiate between a failed testcase and a
failure because the testcase does not exist.
>> >> >> >> >
>> >> >> >> > David
>> >> >> >> >
>> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >> >>
>> >> >> >> >> That's the behavior I expect.  What were you expecting to see?
>> >> >> >> >>
>> >> >> >> >>    David Saff
>> >> >> >> >>
>> >> >> >> >> On Wed, Nov 24, 2010 at 5:53 PM, David <davids@> wrote:
>> >> >> >> >> > I had hoped so but with
>> >> >> >> >> >
>> >> >> >> >> > Result run = (new
org.junit.runner.JUnitCore()).run(Request.method(Try.class, actionWord));
>> >> >> >> >> > System.out.println("Test result: " + run.wasSuccessful() );
>> >> >> >> >> >
>> >> >> >> >> > I get run.wasSuccessful() returning false when the method fails
or it does not exist.
>> >> >> >> >> >
>> >> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >> >> >>
>> >> >> >> >> >> I think that if methodA does not exist, you will get an error
message.
>> >> >> >> >> >>  Do you see different behavior?
>> >> >> >> >> >>
>> >> >> >> >> >>    David
>> >> >> >> >> >>
>> >> >> >> >> >> On Thu, Nov 18, 2010 at 8:47 PM, David <davids@> wrote:
>> >> >> >> >> >> > Hi,
>> >> >> >> >> >> >
>> >> >> >> >> >> > Fantastic advice!
>> >> >> >> >> >> >
>> >> >> >> >> >> > I would also like to tell whether the methodA was actually
executed i.e. does it exist.
>> >> >> >> >> >> >
>> >> >> >> >> >> > Thanks,
>> >> >> >> >> >> > David
>> >> >> >> >> >> >
>> >> >> >> >> >> > --- In junit@yahoogroups.com, David Saff <david@> wrote:
>> >> >> >> >> >> >>
>> >> >> >> >> >> >> David,
>> >> >> >> >> >> >>
>> >> >> >> >> >> >> 1) You want new JUnitCore.run(Request.method(Try.class,
"methodA"));
>> >> >> >> >> >> >> 2) You can't both extend from TestCase and mark your tests
with @Test.
>> >> >> >> >> >> >>  Remove the extends TestCase, and more things will work.
>> >> >> >> >> >> >>
>> >> >> >> >> >> >> Good luck,
>> >> >> >> >> >> >>
>> >> >> >> >> >> >>    David
>> >> >> >> >> >> >>
>> >> >> >> >> >> >> On Mon, Nov 15, 2010 at 8:54 PM, David <davids@> wrote:
>> >> >> >> >> >> >> > In Eclipse I have a project with a package and all my
source code is in the one package.
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > I would like to run JUnit test cases selectively from a
separate Java application where I run the code
>> >> >> >> >> >> >> >      
 org.junit.runner.JUnitCore.main("example.Try.methodA");
>> >> >> >> >> >> >> > in an attempt to run the unit test 'methodA' in my JUnit
test module which looks like this:
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > package example;
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > import org.junit.*;
>> >> >> >> >> >> >> > import junit.framework.TestCase;
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > public class Try extends TestCase
>> >> >> >> >> >> >> > {
>> >> >> >> >> >> >> >        public Try(String name) {
>> >> >> >> >> >> >> >                super(name);
>> >> >> >> >> >> >> >        }
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >        @Before
>> >> >> >> >> >> >> >        public void baseState() {
>> >> >> >> >> >> >> >        }
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >        @Test
>> >> >> >> >> >> >> >        public void methodA() {
>> >> >> >> >> >> >> >        }
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > }
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > I get the error message 'Could not find class:
example.Try.methodA'
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > If I run Try.java as a JUnit Test I get the error
>> >> >> >> >> >> >> > junit.framework.AssertionFailedError: No tests found in
example.Try
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > David
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > ------------------------------------
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > Yahoo! Groups Links
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >>
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > ------------------------------------
>> >> >> >> >> >> >
>> >> >> >> >> >> > Yahoo! Groups Links
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >>
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > ------------------------------------
>> >> >> >> >> >
>> >> >> >> >> > Yahoo! Groups Links
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >>
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > ------------------------------------
>> >> >> >> >
>> >> >> >> > Yahoo! Groups Links
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > ------------------------------------
>> >> >> >
>> >> >> > Yahoo! Groups Links
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > ------------------------------------
>> >> >
>> >> > Yahoo! Groups Links
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>> >
>>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23114 From: Esko Luontola <esko.luontola@...>
Date: Mon Dec 6, 2010 11:29 am
Subject: Re: Re: Unit testing a private method??
egeluontola
Send Email Send Email
 
Mike Forsberg wrote on 5.12.2010 2:17:
> In regards to... why do unit testing at all if everything is tested through
> functional testing.
>
> Personally, if I could get every scenario to run at the
> integration/functional level within the time I can run my unit tests, I'd
> only write unit tests to track down why the higher level tests are failing.
> In this amazing world, a unit test would only be needed to track down a bug
> since my brain is not big enough to hold the whole system in it's mind.
> However, once the bug is fixed, the unit test can grow stale. As I'd be
> assured that every possible scenario is tested.


    SPEED

For me too, the speed of running the tests is important. If it takes
over 5-10 seconds to run all the tests, then I will hesitate to run them
after every change, which in turn will lead to slower feedback and
longer times in finding the reason for a failure: If I run the tests
less often, I will make more changes between running tests, and the
mistake could be in any of those changed lines. But if I run tests after
every one-liner change and the tests break, there is a high probability
that the mistake was on that one line and I will find it quickly.

So I will have near-100% test coverage using unit tests, which I will
run many times per minute; these tests must run at a speed of hundreds
or thousands of tests per second. Then I also have a small set of
end-to-end tests, which I use the verify the existence of features and
that all the components have been plugged together correctly.

P.S. When using Guice, I might have a unit test which creates the Guice
Injector to check that the DI configuration doesn't contain such obvious
errors which Guice's built-in checks will find. But I would not
instantiate the SUT of my unit tests using Guice, because that's slow
(on my C2Q6600 CPU about 5 ms to create the Injector), and because it
would not put as much design pressure on my code (more on that later).


    FOCUS

Another reason is that by writing focused unit tests you can focus
better on making that unit behave correctly in all corner cases (pun
intended).

For example, I was writing a small transactional in-memory database and
had to introduce locking of multiple keys as an atomic group (my
integration tests were sometimes failing due to a concurrency bug - so
at integration level the bug was reproducable, but very
non-deterministic), so I wrote a GroupLock [1] class which I could then
use in the database. What do you think, could all the corner cases
mentioned in [2] be covered reliably with integration tests for a
multi-threaded system?

In the same in-memory database there were also other low-level
components which I test-drove using unit tests, because test-driving
them using higher level tests would not have been possible with small
steps. When I was test-driving the database class, at first I had all
the values in a HashMap, but then when I started to implement
transactions and multiversion concurrency control [3], I basically
needed a versioned Map which remembers some of the previous values,
until there are no active transactions which can read those old
versions. This produced the five Revision* classes at [4], in total over
400 LOC, and I don't see how I could have test-driven those using only
integration tests. So I grew those classes using the four Revision*Spec
tests at [5].

[1]
https://github.com/orfjackal/dimdwarf/blob/master/dimdwarf-core/src/main/java/ne\
t/orfjackal/dimdwarf/db/inmemory/GroupLock.java
[2]
https://github.com/orfjackal/dimdwarf/blob/master/dimdwarf-core/src/test/java/ne\
t/orfjackal/dimdwarf/db/inmemory/GroupLockSpec.java
[3] http://en.wikipedia.org/wiki/Multiversion_concurrency_control
[4]
https://github.com/orfjackal/dimdwarf/tree/master/dimdwarf-core/src/main/java/ne\
t/orfjackal/dimdwarf/db/inmemory
[5]
https://github.com/orfjackal/dimdwarf/tree/master/dimdwarf-core/src/test/java/ne\
t/orfjackal/dimdwarf/db/inmemory


    PRESSURE

Still one more reason why I write unit tests (in addition to end-to-end
tests), is that writing unit tests is more painful [6]. To be able to
test something in isolation, the code needs to be decoupled and
cohesive, and it needs to avoid global state and many other traits of
generally bad design [7]. When dealing with bad code, writing unit tests
causes *more pain* than writing integration tests, which is a *good
thing*, because it leads me to improve the design so that writing the
tests will be easier. This in turn leads into better code and a more
maintainable design. If I would write only integration tests, or even no
tests, then I would be shutting my eyes to the problem points in the
design and there would be no pressure to improve the design.

P.S. In the Growing Object-Oriented Software book the authors say that
also writing end-to-end tests puts design pressure on the system as a
whole, which leads to for example introducing monitoring hooks into the
system. These hooks in turn also happen to be useful for monitoring the
system in production.

[6]
http://blog.orfjackal.net/2010/04/direct-and-indirect-effects-of-tdd.html
[7]
http://googletesting.blogspot.com/2008/08/by-miko-hevery-so-you-decided-to.html

--
Esko Luontola
www.orfjackal.net

#23115 From: "pniederw" <pniederw@...>
Date: Tue Dec 7, 2010 11:07 pm
Subject: Re: Is junit-dep supposed to work without Hamcrest?
pniederw
Send Email Send Email
 
The issue is here: https://github.com/KentBeck/junit/issues/#issue/165

Will this get fixed for 4.9? Causes lots of pain.

Cheers,
Peter

--- In junit@yahoogroups.com, David Saff <david@...> wrote:
>
> The answers are yes, junit-dep should work if you avoid any overt
> hamcrest mentions, and there appears to be a bug.  Can you make sure
> to file the bug at github?  Thanks,
>
>    David Saff

----------------------------------------------------------------
Peter Niederwieser
Creator, http://spockframework.org
Committer, http://groovy.codehaus.org
Chief Engineer, http://smarter-ecommerce.com
Twitter: pniederw

#23116 From: Dale Emery <dale@...>
Date: Wed Dec 15, 2010 10:03 pm
Subject: Why no target parameter on TestRule.apply()?
dhemery...
Send Email Send Email
 
Hi all,

A question arose in response to my blog post about how to write and apply
rules ( http://cwd.dhemery.com/2010/12/junit-rules/ ):

Why does the new TestRule.apply() method not take a target parameter?

Given that the description can tell you everything you want to know about
the test method and test class, I'm guessing that rules would need to
interact directly with targets only rarely. But the question arose, and rare
is not the same as never, so I thought I'd ask those in the know.

Dale

--
Dale Emery
Consultant to software teams and leaders
Web: http://dhemery.com


[Non-text portions of this message have been removed]

#23117 From: David Saff <david@...>
Date: Thu Dec 16, 2010 3:53 pm
Subject: Re: Why no target parameter on TestRule.apply()?
dsaff
Send Email Send Email
 
Great question.  As usual, the docs are lagging the implementation a
bit.  A couple reasons:

1) Most rules don't appear to use the target.
2) 4.9 introduces ClassRules, for which there is no target to supply.
3) Rules that need the target can easily ask for it at creation (see below).
4) There seemed to be some documentation benefit in being able to see
which rules actually used the target.

A (half-hypothetical) example of a rule that can use the target is a
auto-mocker, which can be used thus, with "this" passed into the
Rule's constructor:

public class HasMocks {
    @Rule public Rule mockery = new AutoMocker(this);
    @Mock HttpGrabber http;
    @Mock FileGrabber files;
}

Hope that makes sense, and thanks for the blog post!

    David Saff

On Wed, Dec 15, 2010 at 5:03 PM, Dale Emery <dale@...> wrote:
> Hi all,
>
> A question arose in response to my blog post about how to write and apply
> rules ( http://cwd.dhemery.com/2010/12/junit-rules/ ):
>
> Why does the new TestRule.apply() method not take a target parameter?
>
> Given that the description can tell you everything you want to know about
> the test method and test class, I'm guessing that rules would need to
> interact directly with targets only rarely. But the question arose, and rare
> is not the same as never, so I thought I'd ask those in the know.
>
> Dale
>
> --
> Dale Emery
> Consultant to software teams and leaders
> Web: http://dhemery.com
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23118 From: BenXS <bxstover@...>
Date: Thu Dec 16, 2010 5:06 pm
Subject: In which sequence are testMethods called?
bxstover
Send Email Send Email
 
Assume I have defined a java test class like the one below. In which sequence
are the ´various test methods processed?

- Alphabetically?
- In the order of appearance in the class?

How can I change the order of processing?

Ben

public class ExampleTestCase extends TestCase {

		 public void setUp() {
			 System.out.println("Per Test Case Setup");
		 }

		 public void tearDown() {
			 System.out.println("Per Test Case Teardown");
		 }

		 public void testA() {
			 System.out.println("Test A");
		 }

		 public void testB() {
			 System.out.println("Test B");
		 }

		 public void testC() {
			 System.out.println("Test C");
		 }



}
--
View this message in context:
http://old.nabble.com/In-which-sequence-are-testMethods-called--tp30474480p30474\
480.html
Sent from the JUnit - User mailing list archive at Nabble.com.

#23119 From: David Saff <david@...>
Date: Thu Dec 16, 2010 6:38 pm
Subject: Re: In which sequence are testMethods called?
dsaff
Send Email Send Email
 
Ben,

JUnit uses Java's reflection API, which guarantees nothing with
respect to order:

http://stackoverflow.com/questions/1097807/java-reflection-is-the-order-of-class\
-fields-and-methods-standardized

There are tricks to get your tests running in a particular order.
There are also ways to change your tests so the order is unimportant.
Why are you hoping to change the order?

    David Saff

On Thu, Dec 16, 2010 at 12:06 PM, BenXS <bxstover@...> wrote:
>
> Assume I have defined a java test class like the one below. In which sequence
> are the ´various test methods processed?
>
> - Alphabetically?
> - In the order of appearance in the class?
>
> How can I change the order of processing?
>
> Ben
>
> public class ExampleTestCase extends TestCase {
>
>                public void setUp() {
>                        System.out.println("Per Test Case Setup");
>                }
>
>                public void tearDown() {
>                        System.out.println("Per Test Case Teardown");
>                }
>
>                public void testA() {
>                        System.out.println("Test A");
>                }
>
>                public void testB() {
>                        System.out.println("Test B");
>                }
>
>                public void testC() {
>                        System.out.println("Test C");
>                }
>
>
>
> }
> --
> View this message in context:
http://old.nabble.com/In-which-sequence-are-testMethods-called--tp30474480p30474\
480.html
> Sent from the JUnit - User mailing list archive at Nabble.com.
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23120 From: Dale Emery <dale@...>
Date: Thu Dec 16, 2010 7:46 pm
Subject: Re: Why no target parameter on TestRule.apply()?
dhemery...
Send Email Send Email
 
Hi David,

> A (half-hypothetical) example of a rule that can use the target is a
> auto-mocker, which can be used thus, with "this" passed into the
> Rule's constructor:
>
> public class HasMocks {
> @Rule public Rule mockery = new AutoMocker(this);
> @Mock HttpGrabber http;
> @Mock FileGrabber files;
> }
>
D'oh! It never occurred to me that you could refer to "this" outside a
method. I need to pair more often.

Thanks!

Dale

--
Dale Emery
Consultant to software teams and leaders
Web: http://dhemery.com


[Non-text portions of this message have been removed]

#23121 From: David Saff <david@...>
Date: Fri Dec 17, 2010 5:54 pm
Subject: Re: Why no target parameter on TestRule.apply()?
dsaff
Send Email Send Email
 
On Thu, Dec 16, 2010 at 2:46 PM, Dale Emery <dale@...> wrote:
> Hi David,
>
>> A (half-hypothetical) example of a rule that can use the target is a
>> auto-mocker, which can be used thus, with "this" passed into the
>> Rule's constructor:
>>
>> public class HasMocks {
>> @Rule public Rule mockery = new AutoMocker(this);
>> @Mock HttpGrabber http;
>> @Mock FileGrabber files;
>> }
>>
> D'oh! It never occurred to me that you could refer to "this" outside a
> method. I need to pair more often.

In truth, I had to go double-check with a quick test case before
posting, because I don't do it often...

    David Saff

>
> Thanks!
>
> Dale
>
> --
> Dale Emery
> Consultant to software teams and leaders
> Web: http://dhemery.com
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

#23122 From: Steve Freeman <smgfreeman@...>
Date: Sun Dec 19, 2010 1:55 pm
Subject: Re: Latest preference for organzing test package
smg_freeman
Send Email Send Email
 
That's why I put the test classes in a different package from the production
code:
- if I need intermediate access, then there's probably a cleaner design waiting
to be discovered
- it makes navigation in Idea (based on packages) easier (Eclipse handles this
better)

S

On 26 Nov 2010, at 15:19, Kristian Rosenvold wrote:
> An interesting side-effect of the maven structure is that the unit test
> resides in the same package as the class being tested. This permits the
> use of package-level protection for exposing "non-public" information
> to the test. I know this is generally frowned upon, but sometimes nice
> anyway. Personally I find the semantics of using "protected" so much
> more convoluted (that keyword communicates so many other things), so I
> find package level protection as nice alternative without all the
> feelings that come with "protected".

#23123 From: "Nuca" <ion_petrache2003@...>
Date: Tue Dec 21, 2010 10:35 am
Subject: exclude some tests to run
ion_petrache...
Send Email Send Email
 
Hello all,

I am using an older version of junit (3.8) and I'm having some time consuming
tests that I don't want to run on every build but on some special ones. Those
tests are grouped into a suite. Is it possible to exclude that suite from an ant
script?

Messages 23094 - 23123 of 24386   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help