The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Multithreaded Tests with JUnit
Subject:  better examples?
Date:  2003-08-26 23:55:01
From:  jeanlazarou


I found the goal interresting, but as the example requires "user" validation (in the sake of simplicity) I think the examples are not realistic enough...

I changed the tests and did something like:

> public void testHelloWorld() {
> ByteArrayOutputStream stream = new
> ByteArrayOutputStream();
> PrintStream pStream =
> new PrintStream(stream);
> System.setOut(pStream);
>
> System.out.print("Hello, World!");
>
> assertEquals("Hello, World!",
> stream.toString());
> }

The threaded example:

> public void testHelloWorld() throws
> Throwable {
> ByteArrayOutputStream stream =
> new ByteArrayOutputStream();
> PrintStream pStream =
> new PrintStream(stream);
> System.setOut(pStream);
>
> TestRunnable[] tr = {
> new DelayedHello(5000)};
>
> MultiThreadedTestRunner mtRunner =
> new MultiThreadedTestRunner(tr);
>
> mtRunner.runTestRunnables();
>
> assertEquals("Hello, World!",
> stream.toString());
> }

The bad one is:

> public void testHelloWorld() {
> ByteArrayOutputStream stream =
> new ByteArrayOutputStream();
> PrintStream pStream =
> new PrintStream(stream);
> System.setOut(pStream);
>
> new DelayedHello(5000);
>
> assertEquals("Hello, World!",
> stream.toString());
> }

 Feed java.net RSS Feeds