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...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Messages

Advanced
Messages Help
Messages 16474 - 16503 of 24392   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#16474 From: "kultstatus77" <onlineguy@...>
Date: Tue Apr 11, 2006 7:05 am
Subject: Re: JUnit and automated build process
kultstatus77
Send Email Send Email
 
First of all, thanks for your input to both of you, it was very
helpful. I realize that handing the control to CVS about a test being
written or not (that's essentially what I was proposing) is a bad
idea. Especially the effect on developers can't be underestimated as
it seems. Writing tests should be a help and not a boring task.

About Ant and JUnit: I setup a small example with Ant running JUnit
tests and noticed that it's generally possible to select the tests I'd
like to run via Ant (nothing special about it), the downside being the
necessity to alter the build file every time which is a bad idea. The
default option is to run all existing tests, of course, but certain
situations demand partial test execution only. Is there a way to do
this without messing without Ant's build file? I was thinking of
something similiar like TestNG's feature of grouping tests by name,
but it should work without Java 5

Regards,

Maik

--- In junit@yahoogroups.com, "J. B. Rainsberger" <jbrains@...> wrote:
>
> kultstatus77 wrote:
> > Hi,
> >
> > I'm looking for information on running JUnit tests during an automated
> > build process. I do
> >
> > know that it's possible to include JUnit tasks in Ant's build.xml, but
> > I'm looking for a way
> >
> > to make JUnit tests mandatory for every piece of code that's written
> > and commited to our
> >
> > CVS.
>
> Even if there is a technical solution to this "problem", I would never
> use it. It assumes that 100% of code needs to be tested. While this
> might be a good goal, experience shows that it is not practical. No
> machine can judge whether a given test is worth writing; only humans
can
> do that.
>
> Also, if people write tests only because some machine tells them to,
you
> probably won't see high quality tests.
> --
> J. B. (Joe) Rainsberger :: http://www.jbrains.info
> Your guide to software craftsmanship
> JUnit Recipes: Practical Methods for Programmer Testing
> 2005 Gordon Pask Award for contribution Agile Software Practice
>

#16475 From: "Simon Chappell" <simonpeterchappell@...>
Date: Tue Apr 11, 2006 10:30 am
Subject: Re: Organizing test suites
spchappell
Send Email Send Email
 
On 4/10/06, Cédric Beust ♔ <cbeust@...> wrote:
> On 4/10/06, J. B. Rainsberger <jbrains@...> wrote:
> >
> >
> >
> > The most organizing I do is to have separate source folders for:
> >
> >   * production code
> >   * fast tests
> >   * slow tests
> >   * tests requiring a server environment
> >   * Fit fixtures

I'm with J.B. on this one. Sometimes the simplest thing you can do is
the best thing you can do. I've had great sucess with just physically
organising tests by purpose into separate source folders. It just
works. :-)

> How quaint :-)

Yup, but it works. And most developers can remember to keep their
tests in the appropriate folder.

> Don't you think test groups <http://testng.org> would be a better way to do
> this?  This way the runtime aspect of your tests doesn't impact your
> package/class organization (these two concerns are orthogonal in my
> opinion).

I have no argument that your suggestion is not more sophisticated and
worthy of praise, but at the end of the day, separate source folders
work and even the most easily confused of developers can figure out
where they should put their tests.

An analagy perhaps? If we were trying to get ridd of a mouse: you
could say that you have built a magnificent mousetrap while I have
borrowed the neighbour's cat. Either way, the mouse is in trouble! :-)

Simon

--
www.simonpeter.org

#16476 From: "J. B. Rainsberger" <jbrains@...>
Date: Tue Apr 11, 2006 12:21 pm
Subject: Re: Organizing test suites
nails762
Send Email Send Email
 
Cédric Beust ♔ wrote:
> On 4/10/06, J. B. Rainsberger <jbrains@...> wrote:

>  > The most organizing I do is to have separate source folders for:
>  >
>  >   * production code
>  >   * fast tests
>  >   * slow tests
>  >   * tests requiring a server environment
>  >   * Fit fixtures
>
> How quaint :-)
>
> Don't you think test groups <http://testng.org> would be a better way to do
> this?  This way the runtime aspect of your tests doesn't impact your
> package/class organization (these two concerns are orthogonal in my
> opinion).

No, I don't, because in order to use test groups, I have to annotate
hundreds of tests the same way. Placing them in folders is easier.

As for the orthogonality of those two concerns, I'm not sure I agree: I
definitely find a strong correlation between the two, otherwise what I
do would annoy me strongly, and it doesn't. I don't typically turn slow
tests into fast ones, or the other way around. (I might add a new fast
test and remove an old slow one, but I rarely make a slow test fast by
changing it.)

In JUnit Recipes I postulated the need for ad-hoc test suites to do
things like run all the tests related to a particular defect fix, but
I've never heard a report from the field that anyone actually does that.
I simply don't find test groups useful yet.
--
J. B. (Joe) Rainsberger :: http://www.jbrains.info
Your guide to software craftsmanship
JUnit Recipes: Practical Methods for Programmer Testing
2005 Gordon Pask Award for contribution Agile Software Practice

#16477 From: "Cédric Beust ♔ " <cbeust@...>
Date: Tue Apr 11, 2006 1:38 pm
Subject: Re: Organizing test suites
cbeust
Send Email Send Email
 
On 4/11/06, J. B. Rainsberger <jbrains@...> wrote:
>
>
> No, I don't, because in order to use test groups, I have to annotate
> hundreds of tests the same way. Placing them in folders is easier.


Fair enough, JB.  Test groups are certainly a concept that is not as easy to
retrofit in an existing test hierarchy as moving files around.

--
Cédric
http://testng.org


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

#16478 From: "Wayne Fay" <waynefay@...>
Date: Tue Apr 11, 2006 4:44 am
Subject: Re: JUnit and automated build process
jaeger321
Send Email Send Email
 
First off... While this sounds good in THEORY... You don't ACTUALLY
want to do this...

But if you did... There are "hooks" that the CVS server provides that
let you run code before/after a commit... So you'd basically write a
bash script that would run against the CVS files including the new
files to ensure that your test coverage is still at 100%.

You can find info on the CVS hooks I've mentioned etc online.

Here's a page:
http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/Monitor/LettingCVSPullTh\
eTrigger.rdoc/style/print

Wayne

On 4/10/06, Kevin Klinemeier <zipwow@...> wrote:
> Wouldn't you want to look more at a coverage report, and ensure that it's
> always at 100%?
>
> I don't know about CVS restrictions based on things like this, but you could
> make the build fail, and turn a red lava lamp on or something.
>
> -Kevin
>
> On 4/7/06, kultstatus77 <onlineguy@...> wrote:
> >
> > Hi,
> >
> > I'm looking for information on running JUnit tests during an automated
> > build process. I do
> >
> > know that it's possible to include JUnit tasks in Ant's build.xml, but
> > I'm looking for a way
> >
> > to make JUnit tests mandatory for every piece of code that's written
> > and commited to our
> >
> > CVS. Is there a way to control uploads to CVS regarding JUnit?
> >
> > Another info I'd like to have: is there a way to decide dynamically
> > which tests Ant has to
> >
> > run (like running tests only for changed parts of source code, for
> > example)? I do know that
> >
> > it is common to run all the tests all the time, I'd just like to get
> > to know all the
> >
> > possibilities Ant offers when it comes to JUnit.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

#16479 From: "jineshluke" <jineshluke@...>
Date: Tue Apr 11, 2006 8:54 am
Subject: void method test
jineshluke
Send Email Send Email
 
Hai all

How can i test a public void method and private void method using junit

Please help

Thanks in advance
jinesh

#16480 From: didoss@...
Date: Tue Apr 11, 2006 5:45 pm
Subject: Re: void method test
dijdoss
Send Email Send Email
 
A basic question that has been asked many times before,...

Search Google on your subject line,...you should find an answer there.

  -------------- Original message ----------------------
From: "jineshluke" <jineshluke@...>





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

#16481 From: didoss@...
Date: Tue Apr 11, 2006 5:51 pm
Subject: Re: void method test
dijdoss
Send Email Send Email
 
Actually, Googling on your subject line will answer the first part of your
question,...testing the private method will be less straightforward, but has
also been discussed here, so should be in some archive somewhere - and althought
Joe's book is at home, I suspect that he covers it as well.  :)


  -------------- Original message ----------------------
From: "jineshluke" <jineshluke@...>





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

#16482 From: Kamal Ahmed <KAhmed@...>
Date: Tue Apr 11, 2006 10:51 pm
Subject: Test roundToPeriod
KAhmed@...
Send Email Send Email
 
Hi,

Any ideas/suggestions on how to test the following method using JUnit?

public void roundToPeriod(Calendar inCal) {

         switch (period.getType()) {
         case TimePeriod.TOP_OF_DAY:
         case TimePeriod.TOP_OF_WEEK:
         case TimePeriod.TOP_OF_MONTH: {
             inCal.set(Calendar.HOUR_OF_DAY, 0);
             inCal.set(Calendar.MINUTE, 0);
             break;
         }
         case TimePeriod.HALF_DAY: {
             int hour = (inCal.get(Calendar.AM_PM) == Calendar.AM) ? 0 : 12;
             inCal.set(Calendar.HOUR_OF_DAY, hour);
             inCal.set(Calendar.MINUTE, 0);
             break;
         }
         case TimePeriod.TOP_OF_HOUR: {
             inCal.set(Calendar.MINUTE, 0);
             break;
         }
         case TimePeriod.TOP_OF_MINUTE: {
             break;
         }
         default: {
             inCal.set(Calendar.HOUR_OF_DAY, 0);
             inCal.set(Calendar.MINUTE, 0);
         }
         }
         ;
     }

I was able to test:
case TimePeriod.TOP_OF_DAY:
         case TimePeriod.TOP_OF_WEEK:
         case TimePeriod.TOP_OF_MONTH:

But cannot get code coverage / test for

             inCal.set(Calendar.HOUR_OF_DAY, 0);
             inCal.set(Calendar.MINUTE, 0);


Thanks,
-Kamal.

#16483 From: Andi Mirani <andi_mirani@...>
Date: Wed Apr 12, 2006 12:03 am
Subject: TestCollector
andi_mirani
Send Email Send Email
 
Hi,

   I have with test runner.
   Everytime I test my program in Junit 3.8.1, it has message

   "No test cases found.
   Check that the configured 'TestCollector' is supported on this platform"

   This message was pop up, after I click Run on Junit test interface

   My question is:
   - Is there any problem with the classpath? As you know on the firstime I test
the samples from Junit and it works. But later on, the test case is not work.
I'm embedded java 1.4 and junit tool.

   - How do I solve the problem ?


   Best Regards,

   Andi


---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+
countries) for 2¢/min or less.

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

#16484 From: "greg_plummer" <Greg.plummer@...>
Date: Wed Apr 12, 2006 12:59 pm
Subject: Re: Organizing test suites
greg_plummer
Send Email Send Email
 
--- In junit@yahoogroups.com, "greg_plummer" <Greg.plummer@...> wrote:
>
> Hi All,
>
> We have 2 "AllTests" classes for each package in our system, one
that
> has DB tests and one for everything else. Then we have 2
corresponding
> system-level "AllTests" classes that encompass all the package-
> level "AllTest" classes. Is there an easy and reliabe way to keep
> these "AllTest" classes up to date? It's hard enough to get
everyone
> to write tests, but now they also have to remember to update the
> appropriate "AllTests" classes any time they create a new test
class.
> I hoping there's a pattern or JUnit extension or something that
will
> help with this. Any advice would be greatly appreciated.
>
> Thanks!!!
> Greg Plummer
>

Thanks to everyone who has offered help with this. I liked the JUnit-
addons solution, but there's a lot of red tape to bring new things
into this organization, even open source, so I didn't want to fight
that battle. What we wound up doing was creating an ANT script to
effectively do the same thing that the JUnit-addons solution would
do, since ANT is already an accepted tool here. Thanks again!!!

Greg Plummer

#16485 From: "greg_plummer" <Greg.plummer@...>
Date: Wed Apr 12, 2006 1:07 pm
Subject: Re: JUnit and automated build process
greg_plummer
Send Email Send Email
 
--- In junit@yahoogroups.com, "kultstatus77" <onlineguy@...> wrote:
>
> Hi,
>
> I'm looking for information on running JUnit tests during an
automated
> build process. I do
>
> know that it's possible to include JUnit tasks in Ant's build.xml,
but
> I'm looking for a way
>
> to make JUnit tests mandatory for every piece of code that's written
> and commited to our
>
> CVS. Is there a way to control uploads to CVS regarding JUnit?
>
> Another info I'd like to have: is there a way to decide dynamically
> which tests Ant has to
>
> run (like running tests only for changed parts of source code, for
> example)? I do know that
>
> it is common to run all the tests all the time, I'd just like to get
> to know all the
>
> possibilities Ant offers when it comes to JUnit.
>

You could use the CruiseControl tool for automating your build
process. You can tell it to run the build every time that something
is checked into CVS. I would recommend buying the book "Pragmatic
Project Automation" by Mike Clark. It describes how to automate your
build process, including how to use CruiseControl and how to run to
build when things are checked in to CVS.

#16486 From: Ritesh Singh <ritesh@...>
Date: Wed Apr 12, 2006 4:05 am
Subject: Data driven testing using JUnit
ritesh_cdac
Send Email Send Email
 
Hi,

   How can i write data driven tests in Junit?

   To me it seems that Junit core does not have any concept of data driven
testing. If i want to do it, i will have to write lots of extra code.

   If in my test, i will iterate through the test data, the test will come out
when it will encounter the first failure and will not run for all the test data.

   Regards,
   Ritesh



---------------------------------
Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.

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

#16487 From: "tietyt" <jjjaaannneee@...>
Date: Wed Apr 12, 2006 11:56 pm
Subject: Why can't the JUnit3 GUI Runner run JUnit4 tests?
tietyt
Send Email Send Email
 
When i run my test case in junit3.8.2's junit.swingui.TestRunner
runner, it fails saying:

java.lang.Exception: No runnable methods
	 at
org.junit.internal.runners.TestClassMethodsRunner.testAborted
(TestClassMethodsRunner.java:42)
	 at org.junit.internal.runners.TestClassMethodsRunner.run
(TestClassMethodsRunner.java:33)
	 at org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java:42)
	 at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
	 at org.junit.internal.runners.TestClassRunner.run
(TestClassRunner.java:52)
	 at junit.framework.JUnit4TestAdapter.run
(JUnit4TestAdapter.java:32)

This is my test case (I made it all in one class, but originally i
had the class I was testing and my tests completely separate.  The
error doesn't change either way):

//////////////////// START CODE //////////////////////
package tests;

import org.junit.Test;  //this imports the @Test annotation
import org.junit.Assert;
import org.junit.Before;    //this imports the @Before annotation
import junit.framework.JUnit4TestAdapter;

public class AdderTests {
     private MyNumber one;
     private MyNumber two;

     @Before
     public void doThisForEachTest() {
         one = new MyNumber(1);
         two = new MyNumber(2);
     }

     @Test
     public void successfulTest() {
         Assert.assertEquals(3, one.getValue() + two.getValue());
     }

     @Test
     public void failedTest() {
         Assert.assertEquals(5, one.getValue() + two.getValue());
     }

     public static junit.framework.Test suite() {
         return new JUnit4TestAdapter(AdderTests.class); //this is so
these tests will run on JUnit 3x Runners
     }

     public class MyNumber {
         private int value;

         public int getValue() {
             return value;
         }

         public void setValue(int value) {
             this.value = value;
         }

         public MyNumber(int i) {
             value = i;
         }
     }
}

///////////////////////// END CODE //////////////////////////

Here is the command I'm using to run the JUnit3 gui runner:
/c/jdk1.5/bin/java -classpath "../classes;junit.jar;junit-4.0.jar"
junit.swingui.TestRunner

I'm doing this from within my lib directory.  junit.jar refers to the
the jar with junit3.8.2 code in it (including the gui runner).  I got
the junit-4.0.jar today (4/12/2006) so it should be the latest
version.  And ../classes refers to the directory with my TestCase in
it.

It may be important to note that these tests run as they should when
i use the JUnit4 textui.  Here's the command I use to run that runner:
/c/jdk1.5/bin/java -classpath "../classes;junit-4.0.jar"
junit.textui.TestRunner tests.AdderTests

Here is the output of running that command:
.E.
Time: 0.031
There was 1 error:
1) failedTest(tests.AdderTests)java.lang.AssertionError: expected:<5>
but was:<3>
         at org.junit.Assert.fail(Assert.java:58)
         at org.junit.Assert.failNotEquals(Assert.java:259)
         at org.junit.Assert.assertEquals(Assert.java:80)
         at org.junit.Assert.assertEquals(Assert.java:88)
         at tests.AdderTests.failedTest(AdderTests.java:25)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
         at
org.junit.internal.runners.TestMethodRunner.executeMethodBody
(TestMethodRunner.java:99)
         at org.junit.internal.runners.TestMethodRunner.runUnprotected
(TestMethodRunner.java:81)
         at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestMethodRunner.runMethod
(TestMethodRunner.java:75)
         at org.junit.internal.runners.TestMethodRunner.run
(TestMethodRunner.java:45)
         at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod
(TestClassMethodsRunner.java:71)
         at org.junit.internal.runners.TestClassMethodsRunner.run
(TestClassMethodsRunner.java:35)
         at org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java:42)
         at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestClassRunner.run
(TestClassRunner.java:52)
         at junit.framework.JUnit4TestAdapter.run
(JUnit4TestAdapter.java:32)

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

Thanks for any help

#16488 From: "mikelinuxdehaan" <mikedehaan@...>
Date: Wed Apr 12, 2006 1:46 am
Subject: Adding Tests Dynamically
mikelinuxdehaan
Send Email Send Email
 
I'm trying to add tests to my TestSuite dynamically, but I can't seem
to find a sure-fire way to do it.

Here's my situation:

I have a number of classes in a package (let's say 10 for discussions
sake).  I also have a number of rules that these 10 classes need to
conform to (let's say I have 5 rules).  The only way I can think of
to do this is to write each rule for each of the 10 classes as Tests,
resulting in 50 Tests (5 rules x 10 classes)

TestSuite suite = new TestSuite();

// Test Class1
suite.addTestSuite(TestClass1ConformToRule1.class);
suite.addTestSuite(TestClass1ConformToRule2.class);
suite.addTestSuite(TestClass1ConformToRule3.class);
suite.addTestSuite(TestClass1ConformToRule4.class);
suite.addTestSuite(TestClass1ConformToRule5.class);

// Test Class2
suite.addTestSuite(TestClass2ConformToRule1.class);
suite.addTestSuite(TestClass2ConformToRule2.class);
suite.addTestSuite(TestClass2ConformToRule3.class);
.
.
.

This isn't terrible because I want each rule tested against each
class so if Class1 breaks all the rules, I have 5 failures.

The problem is, my 10 classes will quickly grow to 50 or more, and I
really don't want all this typed into a TestSuite.

What I would like to do is use reflection to grab each of my 10
classes and pass them into my "rule" TestCases.  Something like this:

TestSuite suite = new TestSuite();

for (Iterator classesToTestConformity =
classesFoundWithReflection.iterator(); classesToTestConformity.hasNext
();) {
     Class classToTest = (Class)classesToTestConformity.next();

     suite.addTestSuite(new TestRule1(classToTest));
     suite.addTestSuite(new TestRule2(classToTest));
     suite.addTestSuite(new TestRule3(classToTest));
     suite.addTestSuite(new TestRule4(classToTest));
     suite.addTestSuite(new TestRule5(classToTest));
}

Now I only have to write 5 TestCases instead of 50, and (more
importantly) they are dynamic.  When a programmer on my team adds a
class to the package that needs to conform to these rules, their new
class would automatically be added to the TestSuite and tested.

So, this is my problem.  I can't find a way to initialize my
testSuite with a "class-to-test".  I'm using JUnit 3.8.1 in JDK 1.3.

Does anyone have any ideas?

-Mike

#16489 From: "swetha" <sb_syalamanchili@...>
Date: Thu Apr 13, 2006 7:04 am
Subject: hello friends
sb_syalamanc...
Send Email Send Email
 
i need some help regarding junit.
i was asked to test a j2ee project with junit.
I know that junit doen't support j2ee projects.

i need to support my statements.
i need info of links that supports my statements.
please can any one give me sufficient information y junit can't support
j2ee projects.

swetha

#16490 From: "Antti Karanta" <Antti.Karanta@...>
Date: Wed Apr 12, 2006 5:44 am
Subject: RE: void method test
antti.karant...
Send Email Send Email
 
> Actually, Googling on your subject line will answer the first
> part of your question,...testing the private method will be
> less straightforward, but has also been discussed here, so
> should be in some archive somewhere - and althought Joe's
> book is at home, I suspect that he covers it as well.  :)

   I missed the original question, so I'll answer here.

   Both cases are covered in the FAQ:


   testing a method that does not return anything:
http://junit.sourceforge.net/doc/faq/faq.htm#tests_4

   testing private methods:
http://junit.sourceforge.net/doc/faq/faq.htm#tests_11



      -Antti-

#16491 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri Apr 14, 2006 1:40 am
Subject: Re: hello friends
nails762
Send Email Send Email
 
swetha wrote:

> i need some help regarding junit.
> i was asked to test a j2ee project with junit.
> I know that junit doen't support j2ee projects.

How do you mean that? I test J2EE applications with JUnit all the time.

> i need to support my statements.
> i need info of links that supports my statements.
> please can any one give me sufficient information y junit can't support
> j2ee projects.

I don't think they can, but that depends on what you mean.
--
J. B. (Joe) Rainsberger :: http://www.jbrains.info
Your guide to software craftsmanship
JUnit Recipes: Practical Methods for Programmer Testing
2005 Gordon Pask Award for contribution Agile Software Practice

#16492 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri Apr 14, 2006 1:42 am
Subject: Re: Adding Tests Dynamically
nails762
Send Email Send Email
 
mikelinuxdehaan wrote:
> I'm trying to add tests to my TestSuite dynamically, but I can't seem
> to find a sure-fire way to do it.
>
> Here's my situation:
>
> I have a number of classes in a package (let's say 10 for discussions
> sake).  I also have a number of rules that these 10 classes need to
> conform to (let's say I have 5 rules).  The only way I can think of
> to do this is to write each rule for each of the 10 classes as Tests,
> resulting in 50 Tests (5 rules x 10 classes)

Do these classes implement a common interface or extend a common class?
If they do, then Google "Abstract test case". If not, then they probably
should, so extract an interface for them, then use my previous advice.

Good luck.
--
J. B. (Joe) Rainsberger :: http://www.jbrains.info
Your guide to software craftsmanship
JUnit Recipes: Practical Methods for Programmer Testing
2005 Gordon Pask Award for contribution Agile Software Practice

#16493 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri Apr 14, 2006 1:43 am
Subject: Re: Data driven testing using JUnit
nails762
Send Email Send Email
 
Ritesh Singh wrote:

>   How can i write data driven tests in Junit?
>
>   To me it seems that Junit core does not have any concept of data
> driven testing. If i want to do it, i will have to write lots of extra code.
>
>   If in my test, i will iterate through the test data, the test will
> come out when it will encounter the first failure and will not run for
> all the test data.

You can Google "Parameterized test case" or read _JUnit Recipes_, recipe
4.8. I typically don't write data-driven tests in JUnit anymore, but I
use a Fit ColumnFixture instead. If you know Fit, then I recommend using
it; but if you don't, I would try the Parameterized Test Case pattern first.
--
J. B. (Joe) Rainsberger :: http://www.jbrains.info
Your guide to software craftsmanship
JUnit Recipes: Practical Methods for Programmer Testing
2005 Gordon Pask Award for contribution Agile Software Practice

#16494 From: Stephen Smith <steve@...>
Date: Fri Apr 14, 2006 2:33 am
Subject: Re: Why can't the JUnit3 GUI Runner run JUnit4 tests?
steve@...
Send Email Send Email
 
The clue is in your message subject... JUnit 3.8.x and JUnit 4.x do not
understand one another.

--
Stephen Smith, MEng (Wales).
http://www.stephen-smith.co.uk/

tietyt wrote:
> When i run my test case in junit3.8.2's junit.swingui.TestRunner
> runner, it fails saying:
>
> java.lang.Exception: No runnable methods
>  at
> org.junit.internal.runners.TestClassMethodsRunner.testAborted
> (TestClassMethodsRunner.java:42)
>  at org.junit.internal.runners.TestClassMethodsRunner.run
> (TestClassMethodsRunner.java:33)
>  at org.junit.internal.runners.TestClassRunner$1.runUnprotected
> (TestClassRunner.java:42)
>  at
> org.junit.internal.runners.BeforeAndAfterRunner.runProtected
> (BeforeAndAfterRunner.java:34)
>  at org.junit.internal.runners.TestClassRunner.run
> (TestClassRunner.java:52)
>  at junit.framework.JUnit4TestAdapter.run
> (JUnit4TestAdapter.java:32)
>
> This is my test case (I made it all in one class, but originally i
> had the class I was testing and my tests completely separate.  The
> error doesn't change either way):
>
> //////////////////// START CODE //////////////////////
> package tests;
>
> import org.junit.Test;  //this imports the @Test annotation
> import org.junit.Assert;
> import org.junit.Before;    //this imports the @Before annotation
> import junit.framework.JUnit4TestAdapter;
>
> public class AdderTests {
>     private MyNumber one;
>     private MyNumber two;
>
>     @Before
>     public void doThisForEachTest() {
>         one = new MyNumber(1);
>         two = new MyNumber(2);
>     }
>
>     @Test
>     public void successfulTest() {
>         Assert.assertEquals(3, one.getValue() + two.getValue());
>     }
>
>     @Test
>     public void failedTest() {
>         Assert.assertEquals(5, one.getValue() + two.getValue());
>     }
>
>     public static junit.framework.Test suite() {
>         return new JUnit4TestAdapter(AdderTests.class); //this is so
> these tests will run on JUnit 3x Runners
>     }
>
>     public class MyNumber {
>         private int value;
>
>         public int getValue() {
>             return value;
>         }
>
>         public void setValue(int value) {
>             this.value = value;
>         }
>
>         public MyNumber(int i) {
>             value = i;
>         }
>     }
> }
>
> ///////////////////////// END CODE //////////////////////////
>
> Here is the command I'm using to run the JUnit3 gui runner:
> /c/jdk1.5/bin/java -classpath "../classes;junit.jar;junit-4.0.jar"
> junit.swingui.TestRunner
>
> I'm doing this from within my lib directory.  junit.jar refers to the
> the jar with junit3.8.2 code in it (including the gui runner).  I got
> the junit-4.0.jar today (4/12/2006) so it should be the latest
> version.  And ../classes refers to the directory with my TestCase in
> it.
>
> It may be important to note that these tests run as they should when
> i use the JUnit4 textui.  Here's the command I use to run that runner:
> /c/jdk1.5/bin/java -classpath "../classes;junit-4.0.jar"
> junit.textui.TestRunner tests.AdderTests
>
> Here is the output of running that command:
> .E.
> Time: 0.031
> There was 1 error:
> 1) failedTest(tests.AdderTests)java.lang.AssertionError: expected:<5>
> but was:<3>
>         at org.junit.Assert.fail(Assert.java:58)
>         at org.junit.Assert.failNotEquals(Assert.java:259)
>         at org.junit.Assert.assertEquals(Assert.java:80)
>         at org.junit.Assert.assertEquals(Assert.java:88)
>         at tests.AdderTests.failedTest(AdderTests.java:25)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke
> (NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke
> (DelegatingMethodAccessorImpl.java:25)
>         at
> org.junit.internal.runners.TestMethodRunner.executeMethodBody
> (TestMethodRunner.java:99)
>         at org.junit.internal.runners.TestMethodRunner.runUnprotected
> (TestMethodRunner.java:81)
>         at
> org.junit.internal.runners.BeforeAndAfterRunner.runProtected
> (BeforeAndAfterRunner.java:34)
>         at org.junit.internal.runners.TestMethodRunner.runMethod
> (TestMethodRunner.java:75)
>         at org.junit.internal.runners.TestMethodRunner.run
> (TestMethodRunner.java:45)
>         at
> org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod
> (TestClassMethodsRunner.java:71)
>         at org.junit.internal.runners.TestClassMethodsRunner.run
> (TestClassMethodsRunner.java:35)
>         at org.junit.internal.runners.TestClassRunner$1.runUnprotected
> (TestClassRunner.java:42)
>         at
> org.junit.internal.runners.BeforeAndAfterRunner.runProtected
> (BeforeAndAfterRunner.java:34)
>         at org.junit.internal.runners.TestClassRunner.run
> (TestClassRunner.java:52)
>         at junit.framework.JUnit4TestAdapter.run
> (JUnit4TestAdapter.java:32)
>
> FAILURES!!!
> Tests run: 2,  Failures: 0,  Errors: 1
>
> Thanks for any help
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

#16495 From: Andi Mirani <andi_mirani@...>
Date: Fri Apr 14, 2006 4:44 pm
Subject: TestCollector
andi_mirani
Send Email Send Email
 
Hi all,

   Is there anyone can help me to figure out the TestCollector?
   How I can use the TestCollector in Junit test.

   After I type "java junit.swingui.TestRunner, It always say "No test cases
found. Checked that configured 'TestCollector" is supported on this platform"

   How do I configure the TestCollector?


   Thank you for your help,

   Andi


---------------------------------
Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.

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

#16496 From: "Rajeev Chaudhary" <rajeev2106@...>
Date: Fri Apr 14, 2006 2:26 pm
Subject: Re: hello friends
rajeev2106@...
Send Email Send Email
 
 Hi just tell me which IDE are you using for development


On Thu, 13 Apr 2006 swetha wrote :
>i need some help regarding junit.
>i was asked to test a j2ee project with junit.
>I know that junit doen't support j2ee projects.
>
>i need to support my statements.
>i need info of links that supports my statements.
>please can any one give me sufficient information y junit can't support
>j2ee projects.
>
>swetha
>
>
>
>
>
>
>
>
>
>
>Yahoo! Groups Links
>
>
>
>
>
>


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

#16497 From: "Ritch Linklater" <ritchlink@...>
Date: Fri Apr 14, 2006 5:36 pm
Subject: Unit Testing JPD's (Weblogic Java Process Definitions)
ritchlink
Send Email Send Email
 
Does anyone know if JUNIT supports this or if there is another tool
out there that might?

Thanks

#16498 From: "c61keuper" <c61keuper@...>
Date: Fri Apr 14, 2006 5:55 pm
Subject: TestSuite outside of source code?
c61keuper
Send Email Send Email
 
I am working with WSAD. I can create testcases within my source path
and there is no problem. I was looking not to clutter up the source
package so I created another package for the test cases. I have tried
to import the source package path into the test package so I could
utilize the source objects in the tests.

package UnitTests;

import junit.framework.TestCase;
import org.dbunit.DatabaseTestCase;
import agfg.dx.eric.rf.*;

public class DBTest extends TestCase
{
	 DB aDB = new DB();
}

I am receiving an error stating "aDB is not a valid type".

I am not sure what I have done wrong?? Any help would be appreciated.

#16499 From: "sayali_mani" <sayali_mani@...>
Date: Fri Apr 14, 2006 12:03 pm
Subject: Can i send a mail using junit
sayali_mani
Send Email Send Email
 
Hi,
I want to send a mail saying that the junit test suite has passed or
not .Can i do it .
I know we can use java to do this ,but still need some directions on
this.
Can any1 plz help
Thanks in advance,
Say

#16500 From: "Sumit" <sumitsavla@...>
Date: Fri Apr 14, 2006 2:47 am
Subject: any e-book for junit ...
sumitsavla
Send Email Send Email
 
hi friends

I m final year student of comp engineering ...
we have Project on Junit..

so want e-book for junit ..
plz give any link or mail e-book to me if any1 has ...
my mail-id is sumitsavla@...

- Sumit.

#16501 From: "kultstatus77" <onlineguy@...>
Date: Sat Apr 15, 2006 8:35 am
Subject: Re: TestSuite outside of source code?
kultstatus77
Send Email Send Email
 
I'm a little confused about the import of DatabaseTestCase and your
DBTest class...which one has the application source and which one is
the test case? Or is your source in agfg.dx.eric.rf.* (this is what I
assume)?

Btw, which IDE do you use (if any)? Eclipse for example supports
different source code folders for the same package.

Regards,

Maik

--- In junit@yahoogroups.com, "c61keuper" <c61keuper@...> wrote:
>
> I am working with WSAD. I can create testcases within my source path
> and there is no problem. I was looking not to clutter up the source
> package so I created another package for the test cases. I have tried
> to import the source package path into the test package so I could
> utilize the source objects in the tests.
>
> package UnitTests;
>
> import junit.framework.TestCase;
> import org.dbunit.DatabaseTestCase;
> import agfg.dx.eric.rf.*;
>
> public class DBTest extends TestCase
> {
>  DB aDB = new DB();
> }
>
> I am receiving an error stating "aDB is not a valid type".
>
> I am not sure what I have done wrong?? Any help would be appreciated.
>

#16502 From: "kultstatus77" <onlineguy@...>
Date: Sat Apr 15, 2006 8:36 am
Subject: Re: Can i send a mail using junit
kultstatus77
Send Email Send Email
 
You could use Ant for building and testing your application, Ant
features a "mail" task which can send mails, attach files etc.

Regards,

Maik


--- In junit@yahoogroups.com, "sayali_mani" <sayali_mani@...> wrote:
>
> Hi,
> I want to send a mail saying that the junit test suite has passed or
> not .Can i do it .
> I know we can use java to do this ,but still need some directions on
> this.
> Can any1 plz help
> Thanks in advance,
> Say
>

#16503 From: "Kent Beck" <kentb@...>
Date: Sun Apr 16, 2006 6:41 am
Subject: RE: Why can't the JUnit3 GUI Runner run JUnit4 tests?
kentlbeck
Send Email Send Email
 
Stephen,

JUnit 4 is intended to be backward compatible (correctly running 3.8.x
tests) and forward compatible (correctly running via JUnit4TestAdapter in
3.8.x runners). I don't know why the OP is having trouble with the Swing
runner.

Regards,

Kent Beck
Three Rivers Institute

> -----Original Message-----
> From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On
> Behalf Of Stephen Smith
> Sent: Thursday, April 13, 2006 7:33 PM
> To: junit@yahoogroups.com
> Subject: Re: [junit] Why can't the JUnit3 GUI Runner run JUnit4 tests?
>
> The clue is in your message subject... JUnit 3.8.x and JUnit
> 4.x do not
> understand one another.
>
> --
> Stephen Smith, MEng (Wales).
> http://www.stephen-smith.co.uk/
>
> tietyt wrote:
> > When i run my test case in junit3.8.2's junit.swingui.TestRunner
> > runner, it fails saying:
> >
> > java.lang.Exception: No runnable methods
> >  at
> > org.junit.internal.runners.TestClassMethodsRunner.testAborted
> > (TestClassMethodsRunner.java:42)
> >  at org.junit.internal.runners.TestClassMethodsRunner.run
> > (TestClassMethodsRunner.java:33)
> >  at org.junit.internal.runners.TestClassRunner$1.runUnprotected
> > (TestClassRunner.java:42)
> >  at
> > org.junit.internal.runners.BeforeAndAfterRunner.runProtected
> > (BeforeAndAfterRunner.java:34)
> >  at org.junit.internal.runners.TestClassRunner.run
> > (TestClassRunner.java:52)
> >  at junit.framework.JUnit4TestAdapter.run
> > (JUnit4TestAdapter.java:32)
> >
> > This is my test case (I made it all in one class, but originally i
> > had the class I was testing and my tests completely separate.  The
> > error doesn't change either way):
> >
> > //////////////////// START CODE //////////////////////
> > package tests;
> >
> > import org.junit.Test;  //this imports the @Test annotation
> > import org.junit.Assert;
> > import org.junit.Before;    //this imports the @Before annotation
> > import junit.framework.JUnit4TestAdapter;
> >
> > public class AdderTests {
> >     private MyNumber one;
> >     private MyNumber two;
> >
> >     @Before
> >     public void doThisForEachTest() {
> >         one = new MyNumber(1);
> >         two = new MyNumber(2);
> >     }
> >
> >     @Test
> >     public void successfulTest() {
> >         Assert.assertEquals(3, one.getValue() + two.getValue());
> >     }
> >
> >     @Test
> >     public void failedTest() {
> >         Assert.assertEquals(5, one.getValue() + two.getValue());
> >     }
> >
> >     public static junit.framework.Test suite() {
> >         return new JUnit4TestAdapter(AdderTests.class);
> //this is so
> > these tests will run on JUnit 3x Runners
> >     }
> >
> >     public class MyNumber {
> >         private int value;
> >
> >         public int getValue() {
> >             return value;
> >         }
> >
> >         public void setValue(int value) {
> >             this.value = value;
> >         }
> >
> >         public MyNumber(int i) {
> >             value = i;
> >         }
> >     }
> > }
> >
> > ///////////////////////// END CODE //////////////////////////
> >
> > Here is the command I'm using to run the JUnit3 gui runner:
> > /c/jdk1.5/bin/java -classpath "../classes;junit.jar;junit-4.0.jar"
> > junit.swingui.TestRunner
> >
> > I'm doing this from within my lib directory.  junit.jar
> refers to the
> > the jar with junit3.8.2 code in it (including the gui
> runner).  I got
> > the junit-4.0.jar today (4/12/2006) so it should be the latest
> > version.  And ../classes refers to the directory with my
> TestCase in
> > it.
> >
> > It may be important to note that these tests run as they
> should when
> > i use the JUnit4 textui.  Here's the command I use to run
> that runner:
> > /c/jdk1.5/bin/java -classpath "../classes;junit-4.0.jar"
> > junit.textui.TestRunner tests.AdderTests
> >
> > Here is the output of running that command:
> > .E.
> > Time: 0.031
> > There was 1 error:
> > 1) failedTest(tests.AdderTests)java.lang.AssertionError:
> expected:<5>
> > but was:<3>
> >         at org.junit.Assert.fail(Assert.java:58)
> >         at org.junit.Assert.failNotEquals(Assert.java:259)
> >         at org.junit.Assert.assertEquals(Assert.java:80)
> >         at org.junit.Assert.assertEquals(Assert.java:88)
> >         at tests.AdderTests.failedTest(AdderTests.java:25)
> >         at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at sun.reflect.NativeMethodAccessorImpl.invoke
> > (NativeMethodAccessorImpl.java:39)
> >         at sun.reflect.DelegatingMethodAccessorImpl.invoke
> > (DelegatingMethodAccessorImpl.java:25)
> >         at
> > org.junit.internal.runners.TestMethodRunner.executeMethodBody
> > (TestMethodRunner.java:99)
> >         at
> org.junit.internal.runners.TestMethodRunner.runUnprotected
> > (TestMethodRunner.java:81)
> >         at
> > org.junit.internal.runners.BeforeAndAfterRunner.runProtected
> > (BeforeAndAfterRunner.java:34)
> >         at org.junit.internal.runners.TestMethodRunner.runMethod
> > (TestMethodRunner.java:75)
> >         at org.junit.internal.runners.TestMethodRunner.run
> > (TestMethodRunner.java:45)
> >         at
> > org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod
> > (TestClassMethodsRunner.java:71)
> >         at org.junit.internal.runners.TestClassMethodsRunner.run
> > (TestClassMethodsRunner.java:35)
> >         at
> org.junit.internal.runners.TestClassRunner$1.runUnprotected
> > (TestClassRunner.java:42)
> >         at
> > org.junit.internal.runners.BeforeAndAfterRunner.runProtected
> > (BeforeAndAfterRunner.java:34)
> >         at org.junit.internal.runners.TestClassRunner.run
> > (TestClassRunner.java:52)
> >         at junit.framework.JUnit4TestAdapter.run
> > (JUnit4TestAdapter.java:32)
> >
> > FAILURES!!!
> > Tests run: 2,  Failures: 0,  Errors: 1
> >
> > Thanks for any help
> >
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>

Messages 16474 - 16503 of 24392   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