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 13411 - 13440 of 24384   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#13411 From: Sarath Kummamuru <kcsarath@...>
Date: Thu May 5, 2005 5:20 am
Subject: Re: Re: Running from jar file
kcsarath
Send Email Send Email
 
I am not sure why that is not happenning. You can test any class that
exists and is accessible in the class path with junit. No
Restrictions. !!!! Whether it is in a directory or in a jar file.

Are you sure that the jar file containing the classes you are testing
and the junit jar files included in the class path!?

Also if you tell us what is the error you are getting, it would be easier.

Sarath.


On 5/5/05, Adam <adamcabler@...> wrote:
>
>  Sorry - I'm getting back to this problem again.
>
>  Actually - I did try and its not working, which is why I asked.  If
>  anyone has any [helpful] suggestions, I would appreciate it.
>
>  --- In junit@yahoogroups.com, "J. B. Rainsberger" <jbrains@r...> wrote:
>  > Adam wrote:
>  > >
>  > >
>  > > Hello,
>  > >    I was wondering if its possible to run junit on classes that are in
>  > > a jar file instead of just a plain directory?
>  >
>  > Yes.
>  >
>  > No offence, but you could have just tried it in the same time it would
>  > take for me to type the answer.
>  > --
>  > J. B. (Joe) Rainsberger
>  > Diaspar Software Services
>  > http://www.diasparsoftware.com
>  > Author, JUnit Recipes: Practical Methods for Programmer Testing
>
>
>
>
>
>  ________________________________
>  Yahoo! Groups Links
>
>
> To visit your group on the web, go to:
> http://groups.yahoo.com/group/junit/
>
> 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.

#13412 From: Jason Rogers <jacaetevha@...>
Date: Thu May 5, 2005 1:07 pm
Subject: Re: HOW SHOULD I RUN MY TESTCASE for this simple WS - JUNIT ?
jacaetev
Send Email Send Email
 
Jyoti wrote:

> I am using Weblogic ..  i am new to this and trying to create a simple
> test case for this WS
>
> public class jtest implements com.bea.jws.WebService
> {
>     static final long serialVersionUID = 1L;
>     /** @common:operation */
>     public int square( int i ) {
>         return i * i;
>     }
> }
>
> I know we need to include Junit.jar in lib in Weblogic. Then what
> should be the test case for it and how can i run that in WL.
>
> Any Help would be appreciated


Jyoti,

I don't know anything about WebLogic, but you said "any help would be
appreciated."  Therefore, I offer this:

You don't need to run this through the web service framework in order to
test it.  All you need to do is create a testcase like the following
(fill it out some more) and make sure that your class is on the test's
classpath.

import junit.framework.TestCase;

public class WebServiceTest extends TestCase {
     public void testSquare() {
         jtest instance = new jtest();
         assertEquals(4, instance.square(2));
     }
}

You should spend some time reading the excellent and free documentation
on the junit.org site.

--
Jason Rogers

"I am crucified with Christ: nevertheless I live; yet not I,
but Christ liveth in me: and the life which I now live in
the flesh I live by the faith of the Son of God, who loved
me, and gave himself for me."
     Galatians 2:20

#13413 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:00 pm
Subject: Re: a test pattern ?
nails762
Send Email Send Email
 
Chris Downey wrote:
>  >> Having just started with JUnit and with the idea of writing tests for
>  >> all of my code, I must say that I'm delighted with the results.  Oh -
>  >> I'm not writing much new code.  Most of the unit tests are for code
>  >> that already exists for which I'm fixing bugs.
>
>  > Good luck with that. I strongly recommend you also try to test-drive a
>  > bunch of code, because that will teach you the goal for refactoring the
>  > legacy stuff. If you don't know where you're going, how do you know you
>  > got there?
>
> J.B., I'm probably being block-headed but I don't quite get what you
> mean.  Can you say a little more about that?

If you spend too much time writing tests for existing code, you'll learn
legacy code design techniques. Those are good for working around designs
that are difficult to test, but not necessarily good for designs you can
create from scratch. I recommend that you also spend time writing new
code using TDD ("test-driving") so that you get more feedback as to what
a good, testable design looks like. This way when you add tests to
existing code, you'll know what kind of design to work towards, rather
than just how to get around the existing design.

I hope that is more clear.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13414 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:02 pm
Subject: Re: Java test functionality check list
nails762
Send Email Send Email
 
Gowrysankar Pandava wrote:
>
> Hi
>
> This group giving me so much information about JUNIT ,There are many
> good discussion are here, thats why i keep continuing in this group.
>
> Here is some small favour for me , do u guys (by mistake) if have any
> Java functionality Testing Check List, pls update in this site so that
> its very use full for Testers Like me.
>
> Hay guys sorry for asking this type help which not relating to Junit but
> i need it very urgently.

If I understand you, you are looking for advice on "what should I
test?". For that, I can only recommend some good books, like "Lessons
Learned in Software Testing". Start there and that will help. Of course,
the ideas are not limited to Java applications, but are more about
testing in general.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13415 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:05 pm
Subject: Re: mechanism to maintain session information across testcases?
nails762
Send Email Send Email
 
Akhil Srinivasan wrote:
> HI,
> I have a situation where junit testcases will act a as a client
> sending messages to the server. Based on the message returned my
> testcase will pass or fail.
> Additionally I have to have multiple testcases that will send messages
> using the same connection. Note that the server maintains a session
> information on the client connection.
> How do i share this session information(connection + related crap)
> across testcases, so that i can execute a sequence of testcases which
> will all use the same connection. One mechanism i thought of was
> extending a testcase that will contain the connection and use it as a
> fixture, all testcases will call that as a fixture but how do i shared
> the connection from the fixture to other testcases which them selves
> need to send messages?

I suggest you create a Singleton class only for testing that contains a
single connection to your messaging server. Each test can then simply do
this:

class MyMessagingTestCase extends TestCase ... {
      setUp(){
          connection = TestFixture.getInstance().getMessagingConnection();
      }
      ...
}

Normally I would not recommend using Singleton, but in this case, I
think the resulting code is cleaner. Only in one place does your test
case class know it's using a Singleton.

Good luck.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13416 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:06 pm
Subject: Re: junit-addons :DirectorySuiteBuilder
nails762
Send Email Send Email
 
bkpreddy wrote:
> I have created suites using DirectorySuiteBuilder to automatically
> find tests in each package.(by creating appropriate filters)
>
> Now I need to create a suite (at the top level) to run all the suites
> created at each package level (one per package).
> With junit-addons is there any way that I can add suites automatically
> to a suite (just like adding tests automatically to a suite).

If you want to run all the test suites, then why not simply point
DirectorySuiteBuilder to the root of your project and let it run every
test it can find?
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13417 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:08 pm
Subject: Re: Fresher's Question - Testing API's
nails762
Send Email Send Email
 
Jyoti wrote:
> Hi,
>
>   I am a QA person with some java knowledge. I am testing some API's
> by passing XML as input with different values to Web Services.Tools
> used to buid the application are Web Logic 8.1,J2EE
>
> I need to automate this testing with JUNIT, can anyone suggest how
> and from where to start.
>
>   Example - I am using a webservice createStudent -- and passing the
> XML like this
>
> <StudentBIZ>
>     <cus:studentName>abc</cus:studentName>
>     <cus:password>pass</cus:password>
>     <cus:email>abc@...</cus:email>
>     <cus:firstname>cc</cus:firstname>
>     <cus:lastName>cc</cus:lastName>
> </StudentBIZ>
>
> which returns an XML to me giving the student info.

XMLUnit allows you to verify XML documents. I suggest trying it. If you
know XPath, then you know enough to check each part of the student info
XML you get back for each test. Even if you don't know XPath, you can
write assertions like this:

String expectedXml = "<StudentInfo> ... </StudentInfo>";
assertXMLEqual(expectedXml, myWebService.getResponse(inputXml));

XMLUnit is smart enough to ignore simple differences like whitespace.

Good luck.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13418 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:28 pm
Subject: Re: HOW SHOULD I RUN MY TESTCASE for this simple WS - JUNIT ?
nails762
Send Email Send Email
 
Jyoti wrote:
> I am using Weblogic ..  i am new to this and trying to create a simple
> test case for this WS
>
> public class jtest implements com.bea.jws.WebService
> {
>     static final long serialVersionUID = 1L;
>     /** @common:operation */
>     public int square( int i ) {
>         return i * i;
>     }
> }
>
> I know we need to include Junit.jar in lib in Weblogic. Then what
> should be the test case for it and how can i run that in WL.
>
> Any Help would be appreciated

If you are trying to run server-side tests, then look at the Cactus project.

If you want to run client-side tests, then you have to go through the
normal web service interface. The test runs on the client, but it talks
to the web service through its WSDL/RPC/XML interface.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13419 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:34 pm
Subject: Re: mechanism to maintain session information across testcases?
nails762
Send Email Send Email
 
Cedric Beust wrote:
>  > From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On
>
>  > You should keep in mind that Junit is meant to be a *unit*
>  > testing framework, not a panacea.
>
> Oh trust me, I am well aware of that :-)

It's funny that you two have never really met before this. :)

> It's good to see that you are as well, and the fact that JUnit is only a
> unit-testing framework is what prompted me to create TestNG in the first
> place.

JUnit is optimized for test-driven development, whereas TestNG helps us
test existing code and manage increasingly end-to-end tests as we feel
we need them.

If I were on a real project right now, I'd be finding a way to use them
together, and I don't think that would be difficult. There's all this
damn legacy code out there.

Cedric: what a pity Michael Feathers didn't know more about TestNG when
he was writing his book. I think he could have shown TestNG in one of
its most natural settings: adding tests to existing code.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13420 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu May 5, 2005 8:36 pm
Subject: Re: Re: Running from jar file
nails762
Send Email Send Email
 
Adam wrote:
>
> Sorry - I'm getting back to this problem again.
>
> Actually - I did try and its not working, which is why I asked.  If
> anyone has any [helpful] suggestions, I would appreciate it.

Please describe the specifics of your problem: your classpath, your
command to run the JUnit test runner and the behavior you observe. Is it
a ClassNotFound problem? Something else?
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13421 From: "Cedric Beust" <cbeust@...>
Date: Thu May 5, 2005 8:35 pm
Subject: RE: mechanism to maintain session information across testcases?
cbeust
Send Email Send Email
 
> From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On
> Behalf Of J. B. Rainsberger

> I suggest you create a Singleton class only for testing that
> contains a single connection to your messaging server. Each
> test can then simply do
> this:
>
> class MyMessagingTestCase extends TestCase ... {
>      setUp(){
>          connection =
> TestFixture.getInstance().getMessagingConnection();
>      }
>      ...
> }
>
> Normally I would not recommend using Singleton, but in this
> case, I think the resulting code is cleaner. Only in one
> place does your test case class know it's using a Singleton.

But you are creating a singleton (or a static) to be used just in one
class...  bit of a code smell if you want to be a purist...

t would be better to inject this value as an instance field only in the test
class that will need it.

--
Cédric

#13422 From: "Ilja Preuss" <preuss@...>
Date: Fri May 6, 2005 7:10 am
Subject: RE: mechanism to maintain session information across testcases?
ipreussde
Send Email Send Email
 
Cedric Beust wrote:

> Akhil's problem is clearly not a unit-testing problem

He definitely didn't choose a unit-testing *solution*, and therefore run
into problems using JUnit. I'm not yet sure wether his *original* problem
actually called for unit testing or not...

And I have to admit that unfortunately I don't have enough experience with
acceptance/integration testing to comment on your other points.

Cheers, Ilja

#13423 From: "Ilja Preuss" <preuss@...>
Date: Fri May 6, 2005 7:13 am
Subject: RE: mechanism to maintain session information across testcases?
ipreussde
Send Email Send Email
 
> I will try to give a couple of more details of what i need to
> do. Pardon the long post. I have a (chat server like) server
> using socket connections(so Cactus won't help here). Now the
> client state can be either (connected) or (connected + logged
> in) or (connected+loggedin+inside a room).  Each state
> transition is done by send a message. Now at each stage i
> have a set of testcases to run.

Do you intend to test the client, the server, or both?

Curious, Ilja

#13424 From: "shyju_ak1" <shyju.ak@...>
Date: Thu May 5, 2005 7:28 pm
Subject: hello.
shyju_ak1
Send Email Send Email
 
i am new in this group.i want to know more about junit.
where can i get the source code of junit.
can any body help me to get the source code...
regards
shyju

#13425 From: Jason Rogers <jacaetevha@...>
Date: Fri May 6, 2005 4:14 pm
Subject: Re: hello.
jacaetev
Send Email Send Email
 
shyju_ak1 wrote:

> i am new in this group.i want to know more about junit.
> where can i get the source code of junit.
> can any body help me to get the source code...

junit.org

--
Jason Rogers

"I am crucified with Christ: nevertheless I live; yet not I,
but Christ liveth in me: and the life which I now live in
the flesh I live by the faith of the Son of God, who loved
me, and gave himself for me."
     Galatians 2:20

#13426 From: "Jim McMaster" <jim.mcmaster@...>
Date: Fri May 6, 2005 4:18 pm
Subject: RE: hello.
mcmaster_tat...
Send Email Send Email
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Try http://www.junit.org.  The download includes the full source.


- --
Jim McMaster
mailto:jim.mcmaster@...






________________________________

	 From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On Behalf
Of shyju_ak1
	 Sent: Thursday, May 05, 2005 1:28 PM
	 To: junit@yahoogroups.com
	 Subject: [junit] hello.


	 i am new in this group.i want to know more about junit.
	 where can i get the source code of junit.
	 can any body help me to get the source code...
	 regards
	 shyju






________________________________

	 Yahoo! Groups Links


	 * To visit your group on the web, go to:
		 http://groups.yahoo.com/group/junit/

	 * To unsubscribe from this group, send an email to:
		 junit-unsubscribe@yahoogroups.com
<mailto:junit-unsubscribe@yahoogroups.com?subject=Unsubscribe>

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



-----BEGIN PGP SIGNATURE-----
Version: PGP 8.1

iQA/AwUBQnuYvmaP5l7/atSJEQK4WQCfU3XrfOVMfwl42LIuyw/HjznO9bgAnR+6
xNrI/34jHbAhWszZrHQ24IMV
=DXJT
-----END PGP SIGNATURE-----

#13427 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri May 6, 2005 7:08 pm
Subject: Re: hello.
nails762
Send Email Send Email
 
shyju_ak1 wrote:
> i am new in this group.i want to know more about junit.
> where can i get the source code of junit.
> can any body help me to get the source code...

Yes. Please search the web. Start with just the keyword "JUnit".
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13428 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri May 6, 2005 7:15 pm
Subject: Re: mechanism to maintain session information across testcases?
nails762
Send Email Send Email
 
Cedric Beust wrote:
>  > From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On
>  > Behalf Of J. B. Rainsberger
>
>  > I suggest you create a Singleton class only for testing that
>  > contains a single connection to your messaging server. Each
>  > test can then simply do
>  > this:
>  >
>  > class MyMessagingTestCase extends TestCase ... {
>  >      setUp(){
>  >          connection =
>  > TestFixture.getInstance().getMessagingConnection();
>  >      }
>  >      ...
>  > }
>  >
>  > Normally I would not recommend using Singleton, but in this
>  > case, I think the resulting code is cleaner. Only in one
>  > place does your test case class know it's using a Singleton.
>
> But you are creating a singleton (or a static) to be used just in one
> class...  bit of a code smell if you want to be a purist...

Since I prefer to test objects in isolation, shared test resources is an
underlying code smell. I realize that the OP is testing legacy code, and
so is testing more at the Integration level, so the underlying
underlying design smell is that the production code depends on a real
messaging server.

> t would be better to inject this value as an instance field only in the test
> class that will need it.

If only one test case class ever needs it, then a class-level field
would suffice. If more than one test case class needs it, then a
publicly-accessible class-level field is required.

I suppose it would be easy to write a JUnit test runner that created
JUnit tests so they could share instance-level data, but that would
probably confuse most JUnit users.

Take care.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13429 From: Laurie Harper <laurie@...>
Date: Sat May 7, 2005 2:29 am
Subject: Simulating multiple tests
laurie@...
Send Email Send Email
 
I have a pattern I use frequently when I want to test that a given input
to a function yields the expected result, over a number of inputs. I use
something like:

	 Stirng[][] TESTS = new String[][] {
		 { "input 1", "expect 1" },
		 { "input 2", "expect 2" },
		 { "input 3", "expect 3" },
		 ...
	 };

	 public void testFoo() {
		 for (int i = 0; i < TESTS.length; i++) {
			 String in = TESTS[i][0];
			 String out = TESTS[i][1];
			 String real = functionToTest(in);
			 assertEquals(in, out, real);
		 }
	 }

This suffers from two problems: the first assertion failure causes
subsequent tests to be skipped; and the number of tests run is reported
as 1 rather than TESTS.length. I can live with the second issue :-) but
the first is a bit of a pain.

I  don't want to write a seperate test method for each input / expected
output pair; listing them out this way makes it much more easy to scan
the test cases and see where there are redundant cases or omissions. So...

How can I rewrite testFoo() such that, for each pair in TESTS, a
seperate test is created, run and reported and all tests are run
regardless of errors? Or, alternatively, is there another way do this
that lets me keep my input / expected output pairs grouped together like
this?

I haven't seen anything covering this in the FAQ or elsewhere; if
there's an example somewhere I haven't seen, please just point me to it!

Thanks,

L.

#13430 From: tselva <selva_217@...>
Date: Sat May 7, 2005 9:46 am
Subject: HttpUnit Query
chellu_cit
Send Email Send Email
 
I have a java program that makes use of HttpUnit.I tried connecting to a local
m/c also to the net.When I run it I get the following exception:

Caused by: java.net.ConnectException: Connection refused

I tried setting up proxy connections

conversation.setProxyServer("10.237.9.31",6050);

When this failed I tried

conversation.setProxyServer("10.237.9.31",6050,"110258","sjssjs");
I still continue to get the same exception.
I thought it could be a proxy issue , but ruled that out after testing out the
proxy using the URLConnection class.
Previously , the same program worked fine for me , now it does not work.
What could be the issue?




T.Selvakumar

98841 43300




---------------------------------
Yahoo! Mail
  Stay connected, organized, and protected. Take the tour

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

#13431 From: Elliotte Harold <elharo@...>
Date: Sat May 7, 2005 12:48 pm
Subject: Re: Simulating multiple tests
elharo@...
Send Email Send Email
 
Laurie Harper wrote:

> This suffers from two problems: the first assertion failure causes
> subsequent tests to be skipped; and the number of tests run is reported
> as 1 rather than TESTS.length. I can live with the second issue :-) but
> the first is a bit of a pain.

I've encountered this issue myself in various forms, often when feeding
in data from some external conformance test suite like the OASIS XSLT
test suite or the W3C XML test suite. Mostly I just ignore it. Once the
tests are running, it's no big deal.

The best I've found for handling this is simply to write a program that
reads the input data and then generates a separate test method for each
input, then copy and paste the output of that program into my test
suite. The problem with this approach is that I have to regenerate
everything when the external test suite changes, so mostly I don't bother.

Sometimes if there's a particular failing test case that bedevils me
I'll manually break just that one out into its own test method. Then
I'll write special case logic yo exclude that test from the main method
that tests the rest of the test suite.

--
Elliotte Rusty Harold  elharo@...
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

#13432 From: "Cedric Beust" <cbeust@...>
Date: Sun May 8, 2005 12:02 am
Subject: RE: Simulating multiple tests
cbeust
Send Email Send Email
 
> From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On

> I have a pattern I use frequently when I want to test that a
> given input to a function yields the expected result, over a
> number of inputs. I use something like:
>
>  Stirng[][] TESTS = new String[][] {
> 	 { "input 1", "expect 1" },
> 	 { "input 2", "expect 2" },
> 	 { "input 3", "expect 3" },
> 	 ...
>  };
>
>  public void testFoo() {
> 	 for (int i = 0; i < TESTS.length; i++) {
> 		 String in = TESTS[i][0];
> 		 String out = TESTS[i][1];
> 		 String real = functionToTest(in);
> 		 assertEquals(in, out, real);
> 	 }
>  }
>
> This suffers from two problems: the first assertion failure
> causes subsequent tests to be skipped; and the number of
> tests run is reported as 1 rather than TESTS.length. I can
> live with the second issue :-) but the first is a bit of a pain.

Actually, I'm surprised about the second issue.  Only test methods are
reported, not asserts, so even in the case above, you should only get the
report for one test (testFoo()).

As for the first problem, when I find myself in need of "breaking down an
assert", I defer the results to booleans:

 	 public void testFoo() {
		 boolean succes[] = new boolean[TESTS.length];
 		 for (int i = 0; i < TESTS.length; i++) {
 			 String in = TESTS[i][0];
 			 String out = TESTS[i][1];
 			 String real = functionToTest(in);
			 success[i] = check(in, out, real);
 		 }

And then you assert all the boolean in the array one by one or with a big
&&.

> I  don't want to write a seperate test method for each input
> / expected output pair; listing them out this way makes it
> much more easy to scan the test cases and see where there are
> redundant cases or omissions. So...
>
> How can I rewrite testFoo() such that, for each pair in
> TESTS, a seperate test is created

That's a bit overkill, the ideal way to do this would be to pass parameters
to your test methods.  Which JUnit doesn't support (but TestNG does :-)).


--
Cédric
http://beust.com/weblog

#13433 From: "J. B. Rainsberger" <jbrains@...>
Date: Sun May 8, 2005 1:32 am
Subject: Re: Simulating multiple tests
nails762
Send Email Send Email
 
Laurie Harper wrote:
> I have a pattern I use frequently when I want to test that a given input
> to a function yields the expected result, over a number of inputs. I use
> something like:
>
>       Stirng[][] TESTS = new String[][] {
>             { "input 1", "expect 1" },
>             { "input 2", "expect 2" },
>             { "input 3", "expect 3" },
>             ...
>       };
>
>       public void testFoo() {
>             for (int i = 0; i < TESTS.length; i++) {
>                   String in = TESTS[i][0];
>                   String out = TESTS[i][1];
>                   String real = functionToTest(in);
>                   assertEquals(in, out, real);
>             }
>       }
>
> This suffers from two problems: the first assertion failure causes
> subsequent tests to be skipped; and the number of tests run is reported
> as 1 rather than TESTS.length. I can live with the second issue :-) but
> the first is a bit of a pain.
>
> I  don't want to write a seperate test method for each input / expected
> output pair; listing them out this way makes it much more easy to scan
> the test cases and see where there are redundant cases or omissions. So...
>
> How can I rewrite testFoo() such that, for each pair in TESTS, a
> seperate test is created, run and reported and all tests are run
> regardless of errors? Or, alternatively, is there another way do this
> that lets me keep my input / expected output pairs grouped together like
> this?
>
> I haven't seen anything covering this in the FAQ or elsewhere; if
> there's an example somewhere I haven't seen, please just point me to it!

If you Google "JUnit parameterized test case" you'll likely find some
code on the subject. That, or read _JUnit Recipes_, recipe 4.8. That, or
use Fit/FitNesse instead (a ColumnFixture). That, or try TestNG, which I
understand provides more direct support for parameterized tests.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing

#13434 From: lava kafle <lkafle@...>
Date: Sun May 8, 2005 1:32 am
Subject: Re: Digest Number 1501
lkafle
Send Email Send Email
 
You use import junit.extensions.ActiveTestSuite; for
your kind of parallel test, and

import junit.extensions.RepeatedTest;

for repeated number of tests as mentioned in junit API
  and do according to your need.
JUINT is rich in such functionalities.

--- junit@yahoogroups.com wrote:

> There are 3 messages in this issue.
>
> Topics in this digest:
>
>       1. Re: hello.
>            From: "J. B. Rainsberger"
> <jbrains@...>
>       2. Re: mechanism to maintain session
> information across testcases?
>            From: "J. B. Rainsberger"
> <jbrains@...>
>       3. Simulating multiple tests
>            From: Laurie Harper <laurie@...>
>
>
>
________________________________________________________________________
>
________________________________________________________________________
>
> Message: 1
>    Date: Fri, 06 May 2005 15:08:32 -0400
>    From: "J. B. Rainsberger" <jbrains@...>
> Subject: Re: hello.
>
> shyju_ak1 wrote:
> > i am new in this group.i want to know more about
> junit.
> > where can i get the source code of junit.
> > can any body help me to get the source code...
>
> Yes. Please search the web. Start with just the
> keyword "JUnit".
> --
> J. B. (Joe) Rainsberger
> Diaspar Software Services
> http://www.diasparsoftware.com
> Author, JUnit Recipes: Practical Methods for
> Programmer Testing
>
>
>
________________________________________________________________________
>
________________________________________________________________________
>
> Message: 2
>    Date: Fri, 06 May 2005 15:15:08 -0400
>    From: "J. B. Rainsberger" <jbrains@...>
> Subject: Re: mechanism to maintain session
> information across testcases?
>
> Cedric Beust wrote:
> >  > From: junit@yahoogroups.com
> [mailto:junit@yahoogroups.com] On
> >  > Behalf Of J. B. Rainsberger
> >
> >  > I suggest you create a Singleton class only for
> testing that
> >  > contains a single connection to your messaging
> server. Each
> >  > test can then simply do
> >  > this:
> >  >
> >  > class MyMessagingTestCase extends TestCase ...
> {
> >  >      setUp(){
> >  >          connection =
> >  >
> TestFixture.getInstance().getMessagingConnection();
> >  >      }
> >  >      ...
> >  > }
> >  >
> >  > Normally I would not recommend using Singleton,
> but in this
> >  > case, I think the resulting code is cleaner.
> Only in one
> >  > place does your test case class know it's using
> a Singleton.
> >
> > But you are creating a singleton (or a static) to
> be used just in one
> > class...  bit of a code smell if you want to be a
> purist...
>
> Since I prefer to test objects in isolation, shared
> test resources is an
> underlying code smell. I realize that the OP is
> testing legacy code, and
> so is testing more at the Integration level, so the
> underlying
> underlying design smell is that the production code
> depends on a real
> messaging server.
>
> > t would be better to inject this value as an
> instance field only in the test
> > class that will need it.
>
> If only one test case class ever needs it, then a
> class-level field
> would suffice. If more than one test case class
> needs it, then a
> publicly-accessible class-level field is required.
>
> I suppose it would be easy to write a JUnit test
> runner that created
> JUnit tests so they could share instance-level data,
> but that would
> probably confuse most JUnit users.
>
> Take care.
> --
> J. B. (Joe) Rainsberger
> Diaspar Software Services
> http://www.diasparsoftware.com
> Author, JUnit Recipes: Practical Methods for
> Programmer Testing
>
>
>
________________________________________________________________________
>
________________________________________________________________________
>
> Message: 3
>    Date: Fri, 06 May 2005 22:29:09 -0400
>    From: Laurie Harper <laurie@...>
> Subject: Simulating multiple tests
>
> I have a pattern I use frequently when I want to
> test that a given input
> to a function yields the expected result, over a
> number of inputs. I use
> something like:
>
>  Stirng[][] TESTS = new String[][] {
> 	 { "input 1", "expect 1" },
> 	 { "input 2", "expect 2" },
> 	 { "input 3", "expect 3" },
> 	 ...
>  };
>
>  public void testFoo() {
> 	 for (int i = 0; i < TESTS.length; i++) {
> 		 String in = TESTS[i][0];
> 		 String out = TESTS[i][1];
> 		 String real = functionToTest(in);
> 		 assertEquals(in, out, real);
> 	 }
>  }
>
> This suffers from two problems: the first assertion
> failure causes
> subsequent tests to be skipped; and the number of
> tests run is reported
> as 1 rather than TESTS.length. I can live with the
> second issue :-) but
> the first is a bit of a pain.
>
> I  don't want to write a seperate test method for
> each input / expected
> output pair; listing them out this way makes it much
> more easy to scan
> the test cases and see where there are redundant
> cases or omissions. So...
>
> How can I rewrite testFoo() such that, for each pair
> in TESTS, a
> seperate test is created, run and reported and all
> tests are run
> regardless of errors? Or, alternatively, is there
> another way do this
> that lets me keep my input / expected output pairs
> grouped together like
> this?
>
> I haven't seen anything covering this in the FAQ or
> elsewhere; if
> there's an example somewhere I haven't seen, please
> just point me to it!
>
> Thanks,
>
> L.
>
>
>
>
>
>
>
>
________________________________________________________________________
>
________________________________________________________________________
>
>
>
>
------------------------------------------------------------------------
> Yahoo! Groups Links
>
>
>     junit-unsubscribe@yahoogroups.com
>
=== message truncated ===




__________________________________
Do you Yahoo!?
Make Yahoo! your home page
http://www.yahoo.com/r/hs

#13435 From: lava kafle <lkafle@...>
Date: Mon May 9, 2005 2:34 am
Subject: Re: HttpUnit Query
lkafle
Send Email Send Email
 
You use getcookie, Setcookie, that catch GUID or other
cookie parameters, and after setting them your program
runs.
--- junit@yahoogroups.com wrote:

> There are 5 messages in this issue.
>
> Topics in this digest:
>
>       1. HttpUnit Query
>            From: tselva <selva_217@...>
>       2. Re: Simulating multiple tests
>            From: Elliotte Harold
> <elharo@...>
>       3. RE: Simulating multiple tests
>            From: "Cedric Beust" <cbeust@...>
>       4. Re: Simulating multiple tests
>            From: "J. B. Rainsberger"
> <jbrains@...>
>       5. Re: Digest Number 1501
>            From: lava kafle <lkafle@...>
>
>
>
________________________________________________________________________
>
________________________________________________________________________
>
> Message: 1
>    Date: Sat, 7 May 2005 02:46:12 -0700 (PDT)
>    From: tselva <selva_217@...>
> Subject: HttpUnit Query
>
> I have a java program that makes use of HttpUnit.I
> tried connecting to a local m/c also to the net.When
> I run it I get the following exception:
>
> Caused by: java.net.ConnectException: Connection
> refused
>
> I tried setting up proxy connections
>
> conversation.setProxyServer("10.237.9.31",6050);
>
> When this failed I tried
>
>
conversation.setProxyServer("10.237.9.31",6050,"110258","sjssjs");
> I still continue to get the same exception.
> I thought it could be a proxy issue , but ruled that
> out after testing out the proxy using the
> URLConnection class.
> Previously , the same program worked fine for me ,
> now it does not work.
> What could be the issue?
>
>
>
>
> T.Selvakumar
>
>
> 98841 43300
>
>
>
>
> ---------------------------------
> Yahoo! Mail
>  Stay connected, organized, and protected. Take the
> tour
>
> [Non-text portions of this message have been
> removed]
>
>
>
>
>
>
________________________________________________________________________
>
________________________________________________________________________
>
> Message: 2
>    Date: Sat, 07 May 2005 08:48:16 -0400
>    From: Elliotte Harold <elharo@...>
> Subject: Re: Simulating multiple tests
>
> Laurie Harper wrote:
>
> > This suffers from two problems: the first
> assertion failure causes
> > subsequent tests to be skipped; and the number of
> tests run is reported
> > as 1 rather than TESTS.length. I can live with the
> second issue :-) but
> > the first is a bit of a pain.
>
> I've encountered this issue myself in various forms,
> often when feeding
> in data from some external conformance test suite
> like the OASIS XSLT
> test suite or the W3C XML test suite. Mostly I just
> ignore it. Once the
> tests are running, it's no big deal.
>
> The best I've found for handling this is simply to
> write a program that
> reads the input data and then generates a separate
> test method for each
> input, then copy and paste the output of that
> program into my test
> suite. The problem with this approach is that I have
> to regenerate
> everything when the external test suite changes, so
> mostly I don't bother.
>
> Sometimes if there's a particular failing test case
> that bedevils me
> I'll manually break just that one out into its own
> test method. Then
> I'll write special case logic yo exclude that test
> from the main method
> that tests the rest of the test suite.
>
> --
> Elliotte Rusty Harold  elharo@...
> XML in a Nutshell 3rd Edition Just Published!
> http://www.cafeconleche.org/books/xian3/
>
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim
>
>
>
>
>
________________________________________________________________________
>
________________________________________________________________________
>
> Message: 3
>    Date: Sat, 7 May 2005 17:02:17 -0700
>    From: "Cedric Beust" <cbeust@...>
> Subject: RE: Simulating multiple tests
>
> > From: junit@yahoogroups.com
> [mailto:junit@yahoogroups.com] On
>
> > I have a pattern I use frequently when I want to
> test that a
> > given input to a function yields the expected
> result, over a
> > number of inputs. I use something like:
> >
> >  Stirng[][] TESTS = new String[][] {
> > 	 { "input 1", "expect 1" },
> > 	 { "input 2", "expect 2" },
> > 	 { "input 3", "expect 3" },
> > 	 ...
> >  };
> >
> >  public void testFoo() {
> > 	 for (int i = 0; i < TESTS.length; i++) {
> > 		 String in = TESTS[i][0];
> > 		 String out = TESTS[i][1];
> > 		 String real = functionToTest(in);
> > 		 assertEquals(in, out, real);
> > 	 }
> >  }
> >
> > This suffers from two problems: the first
> assertion failure
> > causes subsequent tests to be skipped; and the
> number of
> > tests run is reported as 1 rather than
> TESTS.length. I can
> > live with the second issue :-) but the first is a
> bit of a pain.
>
> Actually, I'm surprised about the second issue.
> Only test methods are
> reported, not asserts, so even in the case above,
> you should only get the
> report for one test (testFoo()).
>
> As for the first problem, when I find myself in need
> of "breaking down an
> assert", I defer the results to booleans:
>
>   public void testFoo() {
> 	 boolean succes[] = new boolean[TESTS.length];
>  	 for (int i = 0; i < TESTS.length; i++) {
>  		 String in = TESTS[i][0];
>  		 String out = TESTS[i][1];
>  		 String real = functionToTest(in);
> 		 success[i] = check(in, out, real);
>  	 }
>
> And then you assert all the boolean in the array one
> by one or with a big
> &&.
>
> > I  don't want to write a seperate test method for
> each input
> > / expected output pair; listing them out this way
> makes it
> > much more easy to scan the test cases and see
> where there are
> > redundant cases or omissions. So...
> >
> > How can I rewrite testFoo() such that, for each
> pair in
> > TESTS, a seperate test is created
>
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#13436 From: Andrew McDonagh <andrew.mcdonagh@...>
Date: Mon May 9, 2005 10:33 am
Subject: Re: JUnit Corba Status/Healthcheck
andy_ipaccess
Send Email Send Email
 
boston_ronin wrote:

>I am looking to implement a status or healthcheck mechanism that
>would grow off my current unit testing.
>
>Currently to test my Corba work I am running my tests against the
>wrapper classes I use with Corba.  I would like to improve upon this
>(if it's possible and/or a good idea) and test the actual Corba
>framework for availability, etc. in order to implement
>this 'healthcheck'.  Pro's or Con's to testing the framework versus
>testing against my wrapper classes for this purpose?
>
>Is there a pattern/library or website available that will help me
>here?  I'd like to avoid as many of the dumb mistakes as possible out
>of the gate.
>
>Specifically we are using Visibroker 5.2.
>
>Any help/pointers would be appreciated.
>
>Thanks...
>
>
>
>

We use CORBA and decided early on to treat it like any other framework -
wrap it, mock it and leave it alone.

The main reasons were due to CORBAs threadiness, setup teardown costs,
implementation.

Our ORB will auto redirect corba requests directly in memory if both
client and server processes are on the same machine, so you aren't
actually using the code that goes out on to the LAN in this case -
resulting in a kind of false test really.

The fail reason was one of scope for the tests - when does a test stop
being a Unit test and start becoming an Acceptance test. - for us,
making corba requests over a live network, we consider an acceptance test.

HTH

Andrew

#13437 From: Arun J <mail.jak@...>
Date: Mon May 9, 2005 6:35 pm
Subject: Running same tests again with different configuration..
jayarunkumar
Send Email Send Email
 
Folks,

I wanted to run the same set of tests with different underlying
Implementation. Is there a ready mix available for this purpose?

For every run I will change my underlying Implementation and my same
set of tests are run against it.  This should give the results as
testXXX_Impl1, testYYY_Impl1, testXXX_Impl2, testYYY_Impl2 and so forth.

~JAK

#13438 From: "Cedric Beust" <cbeust@...>
Date: Mon May 9, 2005 6:56 pm
Subject: RE: Running same tests again with different configuration..
cbeust
Send Email Send Email
 
> From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On

> I wanted to run the same set of tests with different
> underlying Implementation. Is there a ready mix available for
> this purpose?

Strategy pattern maybe?

Have your suites create instances of the same test class with different
strategy objects.  You create these instances in your suite method (not
quite sure how you would store the various Strategy objects, though, since
you can't keep state with JUnit).

In TestNG, it would look like this:

@Factory
public Object[] create() {
   List result = new ArrayList();
   result.add(new MyTest(new Strategy1());
   result.add(new MyTest(new Strategy2());

   return result.toArray();
}

--
Cédric

#13439 From: Robert Wenner <robert.wenner@...>
Date: Mon May 9, 2005 11:46 pm
Subject: Re: Running same tests again with different configuration..
robertwenner
Send Email Send Email
 
On Monday 09 May 2005 13:35, Arun J wrote:
> I wanted to run the same set of tests with different underlying
> Implementation. Is there a ready mix available for this purpose?
Try inheritance, e.g. an abstract test case.
	 http://c2.com/cgi/wiki?AbstractTestCases

Robert

#13440 From: "Cedric Beust" <cbeust@...>
Date: Mon May 9, 2005 11:54 pm
Subject: RE: Running same tests again with different configuration..
cbeust
Send Email Send Email
 
> From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On

> On Monday 09 May 2005 13:35, Arun J wrote:
> > I wanted to run the same set of tests with different underlying
> > Implementation. Is there a ready mix available for this purpose?
> Try inheritance, e.g. an abstract test case.
>  http://c2.com/cgi/wiki?AbstractTestCases

I don't think AbstractTestCase helps in this case (it's orthogonal to the
question, actually).

The problem is passing different strategies to the same test class and
running your tests on all the different instances of that class (which can
therefore not use statics to maintain its state).

--
Cédric
http://beust.com/weblog

Messages 13411 - 13440 of 24384   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