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: 31224
  • 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 10016 - 10045 of 24385   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#10016 From: Stefan Lischke <lischke@...>
Date: Mon Dec 1, 2003 12:38 pm
Subject: junit test for interfaces
lischke@...
Send Email Send Email
 
hi there,

I have a well defined API and a bunch of different implementations of
this API. I want to make some jUnit Tests for the API using the
interfaces, so that all implementations could be verified against this
API Junit Test.

What is the standard way to do this?
How can i minimize the adaption work for every different implementation.
Is there a way of just testing against the interfaces and maybe just
derrivate one Main class for every implementation.

thanx in advance

#10017 From: Jason <jasonriz@...>
Date: Mon Dec 1, 2003 6:36 pm
Subject: Passing Startup Parameters to Test Cases
jasonriz
Send Email Send Email
 
Hello,

I use the swingui.TestRunner to run my junit unit
tests.  I launch it as follows:

java junit.swingui.TestRunner MDXTestAll

where MDXTestAll is defined as follows:

//BEGIN MDXTestAll
import junit.framework.*;

public class MDXTestAll
{
   public static Test suite()
   {
         TestSuite suite = new TestSuite();
suite.addTest(MDX2ALESample.suite());
         return suite;
   }
}
//END MDXTestAll

and MDX2ALESample is defined thusly:

//BEGIN MDX2ALESample
import junit.framework.*;

public class MDX2ALESample extends TestCase
{
   protected void setUp( )
   {
      //THIS IS WHERE I'd like access to the parameters
   }
   protected void tearDown( ) throws Exception
   {

   }
   public void testSimple() throws Exception
   {

   }
   public static Test suite()
   {
     return new TestSuite(MDX2ALESample.class);
   }
}
//END MDX2ALESample

Things are working great but now I realize that it
would be a big help if I could enter some
configuration parameters on the TestRunner command
line like so:

java junit.swingui.TestRunner MDXTestAll param1 param2
param3

The question then: is this possible?  If it's not how
do people generally pass config parameters to their
unit tests.  I realize I could read a properties file
in setUp( ) but I'd much prefer to read them from the
command line.  Thanks in advance for any replies!

-jason



__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

#10018 From: "Joeckel, Carl" <cjoeckel@...>
Date: Mon Dec 1, 2003 6:53 pm
Subject: xUnit for Cobol
carljoeckel
Send Email Send Email
 
Hi,
Is there an xUnit framework for developing in Cobol?

Thanks,
Carl Joeckel



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

#10019 From: "stevenbroadbent" <stevenbroadbent@...>
Date: Mon Dec 1, 2003 7:00 pm
Subject: newbie - gui problem
stevenbroadbent
Send Email Send Email
 
I have set up Junit, but when I try to run AllTests with the GUI
interace I get a message

"make sure TestCollector is set for this platform"

It cannot find any of the tests I have written.

#10020 From: "J. B. Rainsberger" <jbrains@...>
Date: Mon Dec 1, 2003 7:46 pm
Subject: Re: junit test for interfaces
nails762
Send Email Send Email
 
Stefan Lischke wrote:

> hi there,
>
> I have a well defined API and a bunch of different implementations of
> this API. I want to make some jUnit Tests for the API using the
> interfaces, so that all implementations could be verified against this
> API Junit Test.
>
> What is the standard way to do this?

http://c2.com/cgi/wiki?AbstractTestCases
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10021 From: "J. B. Rainsberger" <jbrains@...>
Date: Mon Dec 1, 2003 7:47 pm
Subject: Re: Passing Startup Parameters to Test Cases
nails762
Send Email Send Email
 
Jason wrote:

> The question then: is this possible?  If it's not how
> do people generally pass config parameters to their
> unit tests.  I realize I could read a properties file
> in setUp( ) but I'd much prefer to read them from the
> command line.  Thanks in advance for any replies!

JVM properties: -Da=123 -Db=456 ...

The parameters... are they application configuration parameters? or test
data? If test data, put it in the tests. If app configuration, build an
app configuration module to make it easier to add more configuration
data later without changing the way you launch your tests.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10022 From: "J. B. Rainsberger" <jbrains@...>
Date: Mon Dec 1, 2003 7:48 pm
Subject: Re: xUnit for Cobol
nails762
Send Email Send Email
 
Joeckel, Carl wrote:
> Hi,
> Is there an xUnit framework for developing in Cobol?

What did your Google search turn up? Last I saw, two years ago, someone
somewhere was starting one.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10023 From: "J. B. Rainsberger" <jbrains@...>
Date: Mon Dec 1, 2003 7:55 pm
Subject: Re: newbie - gui problem
nails762
Send Email Send Email
 
stevenbroadbent wrote:

> I have set up Junit, but when I try to run AllTests with the GUI
> interace I get a message
>
> "make sure TestCollector is set for this platform"
>
> It cannot find any of the tests I have written.

1. What platform are you running?
2. What was your command to launch JUnit?
3. Where are your tests on the classpath?
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10024 From: "Shane Duan" <shane.duan@...>
Date: Mon Dec 1, 2003 7:57 pm
Subject: RE: Re: New JUnit runner in IntelliJ IDEA 4.0
shaneduan
Send Email Send Email
 
Interesting, they must have their own version of JUnit classes, at least
ComparisonFailure class.

How can I put the request on the next version of JUnit so that there are
getters for the texts that are being compared?

Thanks

	 -----Original Message-----
	 From: Dave Astels [mailto:dave@...]
	 Sent: Monday, November 24, 2003 7:05 AM
	 To: junit@yahoogroups.com
	 Subject: [junit] Re: New JUnit runner in IntelliJ IDEA 4.0


	 --- In junit@yahoogroups.com, "J. B. Rainsberger" <jbrains@r...>
wrote:
	 > maxkir1 wrote:
	 >
	 > > Please take a look at this screenshot, looks quete
interesting:
	 > >
	 > > http://www.intellij.com/images/screenshots/junit.png
	 >
	 > Hey... that /is/ cool. A popup window when an assertion fails,
showing
	 > the two objects. I would especially like something like this
when two
	 > big collections compare to be unequal.
	 >
	 > I'd love a popup dialog with the two lists side by side, diff
style.
	 >
	 > Very neat. It almost makes me want to spend the money on IDEA.
:)

	 Or read "Contributing to Eclipse".

	 Dave




Yahoo! Groups Sponsor
ADVERTISEMENT
click here
<http://rd.yahoo.com/SIG=12ce3allm/M=267637.4116732.5333197.1261774/D=eg
roupweb/S=1705006905:HM/EXP=1069772709/A=1853618/R=0/*http://www.netflix
.com/Default?mqso=60178338&partid=4116732>

<http://us.adserver.yahoo.com/l?M=267637.4116732.5333197.1261774/D=egrou
pmail/S=:HM/A=1853618/rand=934613674>

	 To unsubscribe from this group, send an email to:
	 junit-unsubscribe@yahoogroups.com


	 Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .




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

#10025 From: "Shane Duan" <shane.duan@...>
Date: Mon Dec 1, 2003 7:59 pm
Subject: RE: xUnit for Cobol
shaneduan
Send Email Send Email
 
Also I'd recommend you read the book "Test Driven Development".  It
shows you how to create a framework for any language using test-driven
development.  I tried it and it iworked great for me.

Shane

	 -----Original Message-----
	 From: J. B. Rainsberger [mailto:jbrains@...]
	 Sent: Monday, December 01, 2003 11:48 AM
	 To: junit@yahoogroups.com
	 Subject: Re: [junit] xUnit for Cobol


	 Joeckel, Carl wrote:
	 > Hi,
	 > Is there an xUnit framework for developing in Cobol?

	 What did your Google search turn up? Last I saw, two years ago,
someone
	 somewhere was starting one.
	 --
	 J. B. Rainsberger,
	 Diaspar Software Services
	 http://www.diasparsoftware.com :: +1 416 791-8603
	 Let's write software that people understand



Yahoo! Groups Sponsor
ADVERTISEMENT
click here
<http://rd.yahoo.com/SIG=12c8uarp9/M=267637.4116730.5333196.1261774/D=eg
roupweb/S=1705006905:HM/EXP=1070394577/A=1853619/R=0/*http://www.netflix
.com/Default?mqso=60178356&partid=4116730>

<http://us.adserver.yahoo.com/l?M=267637.4116730.5333196.1261774/D=egrou
pmail/S=:HM/A=1853619/rand=892195824>

	 To unsubscribe from this group, send an email to:
	 junit-unsubscribe@yahoogroups.com


	 Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .




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

#10026 From: "carljoeckel" <cjoeckel@...>
Date: Mon Dec 1, 2003 8:11 pm
Subject: Re: xUnit for Cobol
carljoeckel
Send Email Send Email
 
Thanks - Google turned up some text references to CobolUnit, but I
couldn't actually find it anywhere.


--- In junit@yahoogroups.com, "Shane Duan" <shane.duan@b...> wrote:
> Also I'd recommend you read the book "Test Driven Development".  It
> shows you how to create a framework for any language using test-
driven
> development.  I tried it and it iworked great for me.
>
> Shane
>
>  -----Original Message-----
>  From: J. B. Rainsberger [mailto:jbrains@r...]
>  Sent: Monday, December 01, 2003 11:48 AM
>  To: junit@yahoogroups.com
>  Subject: Re: [junit] xUnit for Cobol
>
>
>  Joeckel, Carl wrote:
>  > Hi,
>  > Is there an xUnit framework for developing in Cobol?
>
>  What did your Google search turn up? Last I saw, two years
ago,
> someone
>  somewhere was starting one.
>  --
>  J. B. Rainsberger,
>  Diaspar Software Services
>  http://www.diasparsoftware.com :: +1 416 791-8603
>  Let's write software that people understand
>
>
>
> Yahoo! Groups Sponsor
> ADVERTISEMENT
> click here
>
<http://rd.yahoo.com/SIG=12c8uarp9/M=267637.4116730.5333196.1261774/D=
eg
>
roupweb/S=1705006905:HM/EXP=1070394577/A=1853619/R=0/*http://www.netfl
ix
> .com/Default?mqso=60178356&partid=4116730>
>
> <http://us.adserver.yahoo.com/l?
M=267637.4116730.5333196.1261774/D=egrou
> pmail/S=:HM/A=1853619/rand=892195824>
>
>  To unsubscribe from this group, send an email to:
>  junit-unsubscribe@yahoogroups.com
>
>
>  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/> .
>
>
>
>
> [Non-text portions of this message have been removed]

#10027 From: "J. B. Rainsberger" <jbrains@...>
Date: Mon Dec 1, 2003 8:36 pm
Subject: Re: Re: xUnit for Cobol
nails762
Send Email Send Email
 
carljoeckel wrote:

> Thanks - Google turned up some text references to CobolUnit, but I
> couldn't actually find it anywhere.

Then nothing has happened in two years. Shame.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10028 From: 汪春燕 <neilwang@...>
Date: Tue Dec 2, 2003 1:27 am
Subject: 答复: junit test for interfaces
ncywang2003
Send Email Send Email
 
The better way I think is creating an abstract TestCase class,there you should
make the setup and tearDown method final, and implement all the test method, but
the target object/class you will test should be got by an abstract method, such
as, YourInterface getIntance(). you should extend this abstract class for each
class's testcase implemented the interface, the only thing you should do in the
subclass implementing the getInstance method, in this method you should return
an instance of the concrete class.

for example:

interface YourInterface {
     String methodOne();
     String methodTwo();
}


public class FirstImpl implements  YourInterface{

}

public class SecondImpl implements YourInterface{

}


abstract class YourInterfaceTest extends TestCase{
     private YourInterface _target = null;


     abstract YourInterface getInstance();

     protected final void setUp() throws Exception{
              //TODO:prepare test data

              _target = getInstance();
     }

     protected final void tearDown() throws Exception{
              //TODO:clear all test data
     }

     public void testMethodOne(){
         //TODO:concrete test code
         //     String actValue = _target.methodOne();
     }


     public void testMethodTwo(){
        //TODO:concrete test code
         //     String actValue = _target.methodTwo();
     }
}



for each implement's testcase,the only thing you should do is extending
YourInterfaceTest and implementing the getInstance() method,for example:

   public class FirstImplTest extends YourInterfaceTest{
      public final YourInterface getInstance(){
           return new FirstImpl():
      }
   }


   public class SecondImplTest extends YourInterfaceTest{
      public final YourInterface getInstance(){
           return new Secondmpl():
      }
   }



-----原始邮件-----
发件人: Stefan Lischke [mailto:lischke@...]
发送时间: 2003年12月1日 20:39
收件人: junit@yahoogroups.com
主题: [junit] junit test for interfaces


hi there,

I have a well defined API and a bunch of different implementations of
this API. I want to make some jUnit Tests for the API using the
interfaces, so that all implementations could be verified against this
API Junit Test.

What is the standard way to do this?
How can i minimize the adaption work for every different implementation.
Is there a way of just testing against the interfaces and maybe just
derrivate one Main class for every implementation.

thanx in advance




Yahoo! Groups Sponsor

ADVERTISEMENT
 
<http://rd.yahoo.com/SIG=12cuduhku/M=267637.4116732.5333197.1261774/D=egroupweb/\
S=1705006905:HM/EXP=1070387660/A=1853619/R=0/*http://www.netflix.com/Default?mqs\
o=60178356&partid=4116732> click here
  
<http://us.adserver.yahoo.com/l?M=267637.4116732.5333197.1261774/D=egroupmail/S=\
:HM/A=1853619/rand=543217627>

To unsubscribe from this group, send an email to:
junit-unsubscribe@yahoogroups.com


Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .




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

#10029 From: "veny" <veny@...>
Date: Tue Dec 2, 2003 3:17 am
Subject: FW: Re: how to compare two object
veny@...
Send Email Send Email
 
I am using EqualsBuilder from Apache
(org.apache.commons.lang.builder.EqualsBuilder) which uses Reflection to
compares two object.
http://jakarta.apache.org/commons/lang/api/index.html
Assert.assertTrue(EqualsBuilder.reflectionEquals(obj1, obj2));

Hope it helps.

Veny


-----Original Message-----
From: Ron Jeffries [mailto:ronjeffries@...]
Sent: Sunday, November 30, 2003 9:55 AM
To: junit@yahoogroups.com
Subject: Re: [junit] Re: how to compare two object


On Saturday, November 29, 2003, at 8:48:49 PM, Jeff Grigg wrote:

> And I have God-like authority there.

Not running Windows, I guess? ;->

Ron Jeffries
www.XProgramming.com
It is better to have less thunder in the mouth
and more lightning in the hand.  -- Apache proverb



To unsubscribe from this group, send an email to:
junit-unsubscribe@yahoogroups.com


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

#10030 From: Michael Hill <uly@...>
Date: Tue Dec 2, 2003 3:34 pm
Subject: Re: junit test for interfaces
uly562000
Send Email Send Email
 
Stefan...

Monday, December 1, 2003, 7:38:51 AM, you wrote:

SL> What is the standard way to do this?

Here's how I generally handle it.  It defies the usual JUnit advice of
doing no work in the constructor, but I am basically ill-behaved, and
this is no exception.  :)

Hill

class ABCTestBase extends TestCase
{
       public ABCTestBase(String Name, ABCInstance instance)
       {
              super(name);
              this.instance = instance;
       }

       pubic void testSomething()
       {
             instance.this and that();
             assertThisAndThat()
       }
}

class MikeTest extends ABCTestBase
{
       public MikeTest(String name)
       {
              super(name,new Mike());
       }
}


+------------------------------------+
|   Mike Hill <uly@...>   |
|       Michael Hill Associates      |
|              Software              |
|       Satisfaction Guaranteed      |
+------------------------------------+

#10031 From: "J. B. Rainsberger" <jbrains@...>
Date: Tue Dec 2, 2003 4:22 pm
Subject: Re: junit test for interfaces
nails762
Send Email Send Email
 
Michael Hill wrote:

> Stefan...
>
> Monday, December 1, 2003, 7:38:51 AM, you wrote:
>
> SL> What is the standard way to do this?
>
> Here's how I generally handle it.  It defies the usual JUnit advice of
> doing no work in the constructor, but I am basically ill-behaved, and
> this is no exception.  :)

He uses Parameterized Test Case! Huzzah!

I have been asking the question, does the Parameterized Test Case
pattern eliminate the need for the Abstract Test Case pattern? Here's
one person who uses the former over the latter.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10032 From: Michael Hill <uly@...>
Date: Wed Dec 3, 2003 1:48 am
Subject: Re[2]: junit test for interfaces
uly562000
Send Email Send Email
 
J.B. ....

Tuesday, December 2, 2003, 11:22:40 AM, you wrote:

JBR> I have been asking the question, does the Parameterized Test Case
JBR> pattern eliminate the need for the Abstract Test Case pattern? Here's
JBR> one person who uses the former over the latter.

Whichever pattern one prefers, the more important point is probably
that they both get developers to extend TestCase.  On a more or less
daily basis I come across unbelievably poorly factored TestCase code,
even from folks whose shipping code is pristine.  One's first
derivation off of TestCase is really all it takes to realize that you
can kill tons and tons of dup just by hierarchizing the cases.

A further step in this direction is building testing helpers of
various sorts to share code amongst cases. My most common use for this
is all the file-oriented crap. I don't normally factor my shipping
code so that it opens/closes/deletes files, but such factoring is
super-common in retrofit situations. Even in the event that only one
or two objects do all the work of turning files into streams, one
still has to test those two objects before turning them loose.  When
you're AT'ing, this kind of work is even more common.

Hill


+------------------------------------+
|   Mike Hill <uly@...>   |
|       Michael Hill Associates      |
|              Software              |
|       Satisfaction Guaranteed      |
+------------------------------------+

#10033 From: <chirag.doshi@...>
Date: Wed Dec 3, 2003 9:55 am
Subject: Problem in using the textui.TestRunner
chiragsdoshi
Send Email Send Email
 
Hi

I have the following code in the test suite I have built. Here in the
main method, if I use the junit.textui.TestRunner then I get the
following error.

.F
Time: 0.016
There was 1 failure:
1)
warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError
: No tests found in AllDBIFControllerStubTests
       at
AllDBIFControllerStubTests.main(AllDBIFControllerStubTests.java:33)

FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0

While when I use the junit.swingui.TestRunner all the tests in the 2
TestCases run as expected. Same is the case with the
junit.awtui.TesRunner.
Why does the textui.TestRunner behave differently ?

Are there some changes I need to make in the TestSuite Class ?

public class AllTests
{

     public static void main(String[] args)
     {
         junit.textui.TestRunner.run(AllTests.class);
     }

     public static Test suite()
     {
         TestSuite suite = new TestSuite("Test for default package");
         //$JUnit-BEGIN$
         suite.addTest(new TestSuite(Test1.class));
         suite.addTest(
             new TestSuite(Test2.class));
         //$JUnit-END$
         return suite;
     }
}

Thanks in advance,
Chirag


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

#10034 From: "Amir Kolsky" <kolsky@...>
Date: Wed Dec 3, 2003 12:01 pm
Subject: JUnit.org RSS
kolsky
Send Email Send Email
 
Wouldn't it be nice if we had an RSS feed from JUnit.org?

#10035 From: "Alex De Lara" <alex_de_lara@...>
Date: Wed Dec 3, 2003 9:14 pm
Subject: Your example in Junit group
alex_de_lara
Send Email Send Email
 
Hi Jakob,

In regarding to an example that you, a long time ago
posted here:

http://groups.yahoo.com/group/junit/message/312

Well... I just want to say THANK YOU for a very
elucidative and educative example on good use
of Junit and asserts.
I think many other folks also were able to reap
the benefits of hour you took to write it.

I'll keep this example as a model for others around here.

-Alex

#10036 From: "J. B. Rainsberger" <jbrains@...>
Date: Wed Dec 3, 2003 11:10 pm
Subject: Re: Problem in using the textui.TestRunner
nails762
Send Email Send Email
 
chirag.doshi@... wrote:

> Hi
>
> I have the following code in the test suite I have built. Here in the
> main method, if I use the junit.textui.TestRunner then I get the
> following error.

Change this line

  >     public static void main(String[] args)
  >     {

  >         junit.textui.TestRunner.run(AllTests.class);
to
  >         junit.textui.TestRunner.run(AllTests.suite());
  >     }

The TestSuite(Class) constructor does /not/ look for a suite() method on
the TestSuite class.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10037 From: <chirag.doshi@...>
Date: Thu Dec 4, 2003 5:19 am
Subject: I need a report containing the names of all the testMethods
chiragsdoshi
Send Email Send Email
 
Hi
I need to generate a simple report containing the names of all the
TestCase.testmethods run during the execution. Much like the Call
Hierarchy displayed in Eclispe-junit  runner or in the
swingui.TestRunner.

Is it possible using the textui.TestRunner ?
In the faq I read about ant tasks that can be used to create html
reports. The other way I could achieve I think is by creating a
BaseTestCase from which all my testcases inherit. In the BaseTestCase I
can override the  runBare() method to print the name of each method
being run into a file.

Is there something simpler,neater that can be done ?

Thanks
Chirag



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

#10038 From: "GoldenDog63" <Phillipp.Stoker@...>
Date: Thu Dec 4, 2003 6:04 pm
Subject: textui vs. swingui classloader issue?
GoldenDog63
Send Email Send Email
 
I'm having trouble with what appears to be classloader issues ...
I built the following example to determine if there is a real problem
here. This test simply logs a single message during execution. If I
run the test under the swingui, I get an apache
exception '....SimpleLog does not implement Log' (which is clearly
not the case). This test runs exactly as-is under the textui with no
errors.

Anyone have a clue?

JUnit 3.8.1
JDK 1.3.1_03
Commons-Logging 1.0.3
class compiled to junit/build

Text Command ==>
java -cp junit/build;junit/lib/commons-
logging.jar;junit/lib/junit.3.8.1.jar com.temp.EnvironmentTest
.
Time: 0.05

OK (1 test)

Swing Command ==>
java -cp junit/build;junit/lib/commons-
logging.jar;junit/lib/junit.3.8.1.jar junit.swingui.TestRunner
com.temp.EnvironmentTest

==== code ====
package com.temp;

import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class EnvironmentTest extends TestCase {

     public EnvironmentTest(String s) {
         super(s);
     }

     public void testEnvironment() throws Exception {
         Log log = LogFactory.getLog(this.getClass());
         log.error("Test - Logged Error ...");
     }

     public static TestSuite suite() {
         TestSuite suite = new TestSuite("com.temp.EnvironmentTest");
         suite.addTest(new EnvironmentTest("testEnvironment"));
         return suite;
     }

     public static void main(String[] args) {
         junit.textui.TestRunner.run(suite());
     }
}

TIA

#10039 From: "geektank" <emeade@...>
Date: Thu Dec 4, 2003 6:25 pm
Subject: Re: textui vs. swingui classloader issue?
geektank
Send Email Send Email
 
That sounds like the known classloader problem to me:

http://junit.sourceforge.net/doc/faq/faq.htm#running_8


--- In junit@yahoogroups.com, "GoldenDog63" <Phillipp.Stoker@L...> wrote:
> I'm having trouble with what appears to be classloader issues ...
> I built the following example to determine if there is a real problem
> here. This test simply logs a single message during execution. If I
> run the test under the swingui, I get an apache
> exception '....SimpleLog does not implement Log' (which is clearly
> not the case). This test runs exactly as-is under the textui with no
> errors.
>
> Anyone have a clue?
>
> JUnit 3.8.1
> JDK 1.3.1_03
> Commons-Logging 1.0.3
> class compiled to junit/build
>
> Text Command ==>
> java -cp junit/build;junit/lib/commons-
> logging.jar;junit/lib/junit.3.8.1.jar com.temp.EnvironmentTest
> .
> Time: 0.05
>
> OK (1 test)
>
> Swing Command ==>
> java -cp junit/build;junit/lib/commons-
> logging.jar;junit/lib/junit.3.8.1.jar junit.swingui.TestRunner
> com.temp.EnvironmentTest
>
> ==== code ====
> package com.temp;
>
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> public class EnvironmentTest extends TestCase {
>
>     public EnvironmentTest(String s) {
>         super(s);
>     }
>
>     public void testEnvironment() throws Exception {
>         Log log = LogFactory.getLog(this.getClass());
>         log.error("Test - Logged Error ...");
>     }
>
>     public static TestSuite suite() {
>         TestSuite suite = new TestSuite("com.temp.EnvironmentTest");
>         suite.addTest(new EnvironmentTest("testEnvironment"));
>         return suite;
>     }
>
>     public static void main(String[] args) {
>         junit.textui.TestRunner.run(suite());
>     }
> }
>
> TIA

#10040 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu Dec 4, 2003 10:53 pm
Subject: Re: I need a report containing the names of all the testMethods
nails762
Send Email Send Email
 
chirag.doshi@... wrote:

> Hi
> I need to generate a simple report containing the names of all the
> TestCase.testmethods run during the execution. Much like the Call
> Hierarchy displayed in Eclispe-junit  runner or in the
> swingui.TestRunner.
>
> Is it possible using the textui.TestRunner ?
> In the faq I read about ant tasks that can be used to create html
> reports. The other way I could achieve I think is by creating a
> BaseTestCase from which all my testcases inherit. In the BaseTestCase I
> can override the  runBare() method to print the name of each method
> being run into a file.
>
> Is there something simpler,neater that can be done ?

You need to either customize your TestCase or the TestRunner.

The other possibility is to use the JUnit-addons Test Runner, which
allows you to register a test listener. You could write a test listener
that collects test names and prints them out somehow. It's quite simple,
really. Google "Junit-addons test runner".
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10041 From: "GoldenDog63" <Phillipp.Stoker@...>
Date: Thu Dec 4, 2003 7:03 pm
Subject: Re: textui vs. swingui classloader issue?
GoldenDog63
Send Email Send Email
 
That was it. Thanks for the help, I didn't hit that question when
searched the faq. It works either by 'unchecking' the reload, or by
putting the org.apache.commons.logging.* in the properties.

Thanks

--- In junit@yahoogroups.com, "geektank" <emeade@o...> wrote:
> That sounds like the known classloader problem to me:
>
> http://junit.sourceforge.net/doc/faq/faq.htm#running_8
>
>
> --- In junit@yahoogroups.com, "GoldenDog63" <Phillipp.Stoker@L...>
wrote:
> > I'm having trouble with what appears to be classloader issues ...
> > I built the following example to determine if there is a real
problem
> > here. This test simply logs a single message during execution. If
I
> > run the test under the swingui, I get an apache
> > exception '....SimpleLog does not implement Log' (which is
clearly
> > not the case). This test runs exactly as-is under the textui with
no
> > errors.
> >
> > Anyone have a clue?
> >
> > JUnit 3.8.1
> > JDK 1.3.1_03
> > Commons-Logging 1.0.3
> > class compiled to junit/build
> >
> > Text Command ==>
> > java -cp junit/build;junit/lib/commons-
> > logging.jar;junit/lib/junit.3.8.1.jar com.temp.EnvironmentTest
> > .
> > Time: 0.05
> >
> > OK (1 test)
> >
> > Swing Command ==>
> > java -cp junit/build;junit/lib/commons-
> > logging.jar;junit/lib/junit.3.8.1.jar junit.swingui.TestRunner
> > com.temp.EnvironmentTest
> >
> > ==== code ====
> > package com.temp;
> >
> > import junit.framework.TestCase;
> > import junit.framework.TestSuite;
> > import org.apache.commons.logging.Log;
> > import org.apache.commons.logging.LogFactory;
> >
> > public class EnvironmentTest extends TestCase {
> >
> >     public EnvironmentTest(String s) {
> >         super(s);
> >     }
> >
> >     public void testEnvironment() throws Exception {
> >         Log log = LogFactory.getLog(this.getClass());
> >         log.error("Test - Logged Error ...");
> >     }
> >
> >     public static TestSuite suite() {
> >         TestSuite suite = new TestSuite
("com.temp.EnvironmentTest");
> >         suite.addTest(new EnvironmentTest("testEnvironment"));
> >         return suite;
> >     }
> >
> >     public static void main(String[] args) {
> >         junit.textui.TestRunner.run(suite());
> >     }
> > }
> >
> > TIA

#10042 From: Michael Hill <uly@...>
Date: Fri Dec 5, 2003 2:40 am
Subject: Re: textui vs. swingui classloader issue?
uly562000
Send Email Send Email
 
Hey...

The key is the statics that our friend the logger wants inited. This
will come up over and over again. log4j, much of the jdbc stuff, and
several other common apache/jakarta/netforge sources suffer from the
trouble.

In general, it's the price we pay for the quality of the GOF book:
since a great many folks have munged the singleton pattern to make it
the global-variable-initialized-before-the-run pattern, it frequently
comes up in factory situations or when there are properties files to
be read.

Increasingly, I am coming to believe that the word static should
constitute a smell all by itself.

Seeya,
Hill



+------------------------------------+
|   Mike Hill <uly@...>   |
|       Michael Hill Associates      |
|              Software              |
|       Satisfaction Guaranteed      |
+------------------------------------+

#10043 From: "Andrew Wilson" <andrew@...>
Date: Fri Dec 5, 2003 5:55 am
Subject: JUnit Group Test
anewilson
Send Email Send Email
 
Gday, I wondered whether anyone had any comments on this, particular
on whether you are interested in integrating into JUnit.

I have been a fan of JUnit for a number of years now, having seen all
its benefits in a number of projects at major Investment Banks.
However, as I wrote more tests I began to see patterns emerging.
Particularly, I found that as my tests became more complicated I
required true objects rather than the simple
setUp/tearDown/testMe/testMeToo type construction.  I noticed the
following:

h A lot of my test methods were very similar, testing with some
slightly different parameters.  I wanted to define one generic test,
not many similar ones.
h I wanted the other tests to continue if one failed.  Note that
GroboUtils provides this sort of SoftAssert, but you need to define
each test in a separate method.

To implement my tests you just have to implement one very simple
Interface:

public interface GroupTestable {
     /**
      * Usually this would look at an array or an XML file to count
the tests.
      * @return How many tests there are
      */
     public int getNumberOfTests() throws Exception;

     /**
      * Again this would look at an array or an XML file to get the
test name.
      * @param testNo Get the name of the test with the given number
      */
     public String getTestName(int testNo) throws Exception;

     /**
      * Run a particular test, this would probably be getting data out
of an
      * array or an XML file to run the particular test.
      * @param testNo The number of the test to run
      */
     public void runTest(int testNo) throws Exception;
}

Here is a very simple sample implementation:

public class SampleGroupTest extends TestSuite implements
GroupTestable
{
     public static Test suite() throws Throwable {
         return GroupTest.getTestSuite(new SampleGroupTest(), true);
     }

     private SampleGroupTest() { /* do some useful set up for the
tests here */ }

     public int getNumberOfTests() throws Exception { return 3; }

     public String getTestName(int i) throws Exception {
return "Test " + i; }

     public void runTest(int i) throws Exception {
         System.out.println("Running test # " + i);
         if(i==0) {
             Assert.fail("Problem");
         } else if(i==1) {
             throw new Exception("Exception");
         } else {
             // Pass the final test.
         }
     }
}

And if you run this in any standard Junit runner you will get the
following output:

FAILURES!!!
Tests run: 3,  Failures: 1,  Errors: 1

So as expected, one test passed, one failed and one got an
exception.  The other tests continued after the first one failed and
multiple tests were run from a single method.

This code becomes more useful when you start to define your tests
using Arrays or XML.  I managed to define 50 useful tests to my
server in a single XML file.  Now, when I want to add a new test, I
just add some XML to the file and the new testcase runs
automatically.  Imagine the mess if I had to add a new method for
each test!
So how do I do this trickery?
What Im actually doing is overriding the runTest() method in TestCase
to call my particular test., I would like to see this code integrated
into JUnit or GroboUtils (I dont like maintaining infrastructure).

public class GroupTest {
     private static final Category CAT = Category.getInstance
(GroupTest.class.getName());

     private static int counter = 0;    // A counter for which test we
are on.
     private static GroupTestable suit; // The test suite we are
testing.
     private static boolean mShutdownAfterTests;

     public static Test getTestSuite(GroupTestable mySuit, boolean
shutdownAfterTests) throws Exception {
         mShutdownAfterTests = shutdownAfterTests;
         suit = mySuit;
         TestSuite ts = new TestSuite();
         int noOfTests = suit.getNumberOfTests();
         for(int i=0;i<noOfTests;i++) {
             ts.addTestSuite(GenericTestCase.class);
         }
         GroupTest.counter = 0;  // reset counter for running tests.
         return ts;
     }

     public static class GenericTestCase extends TestCase {
         /**
          * Constructor with correct name.
          */
         public GenericTestCase(String name) throws Exception {
             super(suit.getTestName(counter++));
          }

         /**
          * Override the run test method to call our test method.
          */
         public void runTest() throws Exception {
             try {
                 String description = "test #" + counter + " : " +
suit.getTestName(counter);
                 CAT.info("Running " + description);
                 suit.runTest(counter++);
                 CAT.info("Succeeded for " + description);
             } finally {
                 // See whether we should shut down for the last test.
                 if(mShutdownAfterTests && counter ==
suit.getNumberOfTests() ) {
                     System.out.println("Calling exit");
                     ShutdownHandler.getInstance
().shutdownServerCleanly();
                 }
             }
         }

         /**
          * Dummy to trick JUnit
          */
         public void testDummy() throws Exception {
             throw new Exception("This should not be called - it is a
dummy method required to fool JUnit");
         }
     }
}
Conclusion
If you have a lot of tests which look very similar and you dont want
to write a separate method for each one this might help you!  Because
it implements the TestSuite interface it will conform to all the
standard Junit architecture (eg. Maven, Cruise Control etc).
Background Reading
http://www.junit.org V Junit Website.
http://groboutils.sourceforge.net V Junit extensio

#10044 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri Dec 5, 2003 4:26 pm
Subject: Re: textui vs. swingui classloader issue?
nails762
Send Email Send Email
 
Michael Hill wrote:

  > Increasingly, I am coming to believe that the word static should
> constitute a smell all by itself.

Yes, especially when programmers use it as a substitute for the missing
keyword "namespace". Maybe it's a language smell.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#10045 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri Dec 5, 2003 4:28 pm
Subject: Re: JUnit Group Test
nails762
Send Email Send Email
 
Andrew Wilson wrote:

> What Im actually doing is overriding the runTest() method in TestCase
> to call my particular test., I would like to see this code integrated
> into JUnit or GroboUtils (I dont like maintaining infrastructure).

It looks like you've independently implemented the Parameterized Test
Case pattern: set fixture through the constructor and override runTest().

In a few months I'll have the energy to write some articles, a little
will go into the book... but the bottom line is that this is essentially
what I do in order to execute multiple similar tests on different data.
The next step is the Parameterized Test Suite, which is a Parameterized
Test Case that executes all the test*() methods on the same fixture
automatically. I'll write about that later.

Take care.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

Messages 10016 - 10045 of 24385   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