Custom Runner Example

View: New views
5 Messages — Rating Filter:   Alert me  

Custom Runner Example

by Brett L. Schuchert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I was looking for an example of writing a custom runner and didn't
have a lot of luck, so I cracked open the source and figured something
out. If you're interested, have a look here:
http://schuchert.wikispaces.com/CustomJUnit4Runner

I'd appreciate comments on how I could have done that better/easier.

Thanks,

Brett


Re: Custom Runner Example

by jayasinghe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

The sample looks straight-forward and quite promising. You mention in your article that this runner requires JUnit 4.4 in order to run. What exactly hindered you to you a prior version?

Best Regards,
Robin

Brett L. Schuchert wrote:
I was looking for an example of writing a custom runner and didn't
have a lot of luck, so I cracked open the source and figured something
out. If you're interested, have a look here:
http://schuchert.wikispaces.com/CustomJUnit4Runner

I'd appreciate comments on how I could have done that better/easier.

Thanks,

Brett

Re: Custom Runner Example

by Brett L. Schuchert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well the bare minimum was JUnit 4 I suppose because I wanted to use
the @RunWith annotation - was there an easy way to write custom
runners prior to JUnit 4?

As for 4.4 versus earlier versions, it has to do with classes
available in the release. For example, JUnit4Runner is an internal
class (I know I should not depend on internal classes but it made the
work so easy).

So the Eclipse version, which ships with JUnit 4.3 could not depend on
the same base class as the JUnit 4.4-based version, which ships with
IntelliJ.

So, really, the only limitation is my use of an internal class.

Also, I *think* the version of the jar that ships with Eclipse is
missing the classes in the internal package.

--- In junit@..., jayasinghe <robin.desilva@...> wrote:
>
>
> Hi!
>
> The sample looks straight-forward and quite promising. You mention
in your
> article that this runner requires JUnit 4.4 in order to run. What
exactly

> hindered you to you a prior version?
>
> Best Regards,
> Robin
>
>
> Brett L. Schuchert wrote:
> >
> > I was looking for an example of writing a custom runner and didn't
> > have a lot of luck, so I cracked open the source and figured something
> > out. If you're interested, have a look here:
> > http://schuchert.wikispaces.com/CustomJUnit4Runner
> >
> > I'd appreciate comments on how I could have done that better/easier.
> >
> > Thanks,
> >
> > Brett
> >
> >
> >
>
> --
> View this message in context:
http://www.nabble.com/Custom-Runner-Example-tp17538231p17693142.html
> Sent from the JUnit - User mailing list archive at Nabble.com.
>



Re: Re: Custom Runner Example

by David Saff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jun 20, 2008 at 10:42 PM, Brett L. Schuchert
<schuchert@...> wrote:
> Well the bare minimum was JUnit 4 I suppose because I wanted to use
> the @RunWith annotation - was there an easy way to write custom
> runners prior to JUnit 4?

Not at all (for the current definition of "custom runners").

> As for 4.4 versus earlier versions, it has to do with classes
> available in the release. For example, JUnit4Runner is an internal
> class (I know I should not depend on internal classes but it made the
> work so easy).

As extenders may have noticed, with 4.5, we're trying to be kinder to
people that have extended internal classes in 4.4, and will likely
continue a kinder social contract into the future.  We've found that
it's taken a long while to settle on the internal structure of the
default JUnit 4 class runner, so it's going to stay in the internal
package for at least another version, to indicate that this code is
still much less stable than the public API's, but we'll work harder to
make sure that custom runners that compile without deprecation
warnings in 4.(x) will still work in 4.(x+1).

> So the Eclipse version, which ships with JUnit 4.3 could not depend on
> the same base class as the JUnit 4.4-based version, which ships with
> IntelliJ.

I didn't know IntelliJ had caught up.  Good for them.

> Also, I *think* the version of the jar that ships with Eclipse is
> missing the classes in the internal package.

I don't think that's true.  What led you to think that?

Thanks,

   David Saff

Re: Custom Runner Example

by David Saff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Brett,

Sorry it's been so long since your original post.  This is a good
effort.  A few potential simplifications:

1) I think you could have a single IgnoringRunner, like so:

public class IgnoringRunner extends Runner {
  private Runner delegate;

  public IgnoringRunner(Runner delegate) {
    this.delegate = delegate;
  }

  public Description getDescription() {
    return delegate.getDescription();
  }

    @Override
    public void run(RunNotifier notifier) {
       for (Description each : getDescription().getChildren())
          notifier.testIgnored(each);
    }
}

Then, createRunnerFor() could call new IgnoringRunner(new
JUnit4ClassRunner(clazz)), etc.

Would that work?

   David Saff

On Thu, May 29, 2008 at 10:43 AM, Brett L. Schuchert
<schuchert@...> wrote:

> I was looking for an example of writing a custom runner and didn't
> have a lot of luck, so I cracked open the source and figured something
> out. If you're interested, have a look here:
> http://schuchert.wikispaces.com/CustomJUnit4Runner
>
> I'd appreciate comments on how I could have done that better/easier.
>
> Thanks,
>
> Brett
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>
LightInTheBox - Buy quality products at wholesale price