Loading last listened list... » Charts

Nov 7 2011

Running only a group of test classes

Published by sld at 14:43 under English and tagged , , ,

Here’s how to run only a selected group of test classes. Specify your own Runner if you’re not using Mockito.

import java.util.ArrayList;
import java.util.List;

import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
import org.mockito.runners.MockitoJUnitRunner;

public class SelectedTestsRunner implements Runnable {

  public static void main(final String[] args) throws Throwable {
    final SelectedTestsRunner tests =
        new SelectedTestsRunner(new RunnerBuilder() {
          @Override
          public Runner runnerForClass(final Class<?> theClass)
              throws Throwable {
            return new MockitoJUnitRunner(theClass);
          }
        });
    tests.add(MyTestClass1.class);
    tests.add(MyTestClass2.class);
    tests.run();
  }

  private final RunnerBuilder builder;

  private final List<Class<?>> tests;

  public SelectedTestsRunner(final RunnerBuilder builder) {
    this.builder = builder;
    tests = new ArrayList<Class<?>>();
  }

  private void add(final Class<?> testClass) {
    tests.add(testClass);
  }

  @Override
  public void run() {
    Runner runner = null;
    try {
      runner = new Suite(builder, tests.toArray(new Class[0]));
    } catch (final InitializationError e) {
      e.printStackTrace();
      return;
    }

    final RunNotifier notifier = new RunNotifier();
    final ProgressListener progressListener = new ProgressListener();
    notifier.addListener(progressListener);
    runner.run(notifier);

    final StringBuilder status = new StringBuilder();
    status.append(”\nSuccessful: ” + progressListener.getSuccessCount());
    status.append(”\n    Failed: ” + progressListener.getFailCount());

    System.err.println(status.toString());
    progressListener.processFails(new FailProcessor() {
      @Override
      public void process(final Failure failure) {
        if (failure.getException() != null) {
          failure.getException().printStackTrace();
        }
      }
    });
  }

  private static class ProgressListener extends RunListener {

    private final List<Failure> fails = new ArrayList<Failure>();

    private final List<Description> finished = new ArrayList<Description>();

    @Override
    public void testFinished(final Description description) throws Exception {
      super.testFinished(description);
      finished.add(description);
    }

    @Override
    public void testFailure(final Failure failure) throws Exception {
      super.testFailure(failure);
      fails.add(failure);
    }

    public int getSuccessCount() {
      return finished.size() - fails.size();
    }

    public int getFailCount() {
      return fails.size();
    }

    public void processFails(final FailProcessor processor) {
      for (final Failure fail : fails) {
        processor.process(fail);
      }
    }

  }

  private interface FailProcessor {
    void process(Failure failure);
  }

}

No responses yet

Mar 19 2008

Travel Freely

Published by sld at 9:16 under English

R.I.P.
Sir Arthur C. Clarke.
1917-2008

No responses yet

Jan 27 2008

Térképpel szűrni

Published by sld at 21:24 under Magyar and tagged ,

Kéretlen reklám… De annyira megtetszett hogy tessék: realorigo. Használható, Google Maps, normális szűrés mindenre ami nekem kellett. Örülök hogy van ilyen. Majdnem lefelejtettem: ingatlankereső.

No responses yet

Nov 2 2007

Worlds

Published by sld at 22:54 under English and tagged , ,

Sir Arthur C. Clarke writes in the Foreword of 2001: A Space Odyssey:

Behind every man now alive stand thirty ghosts, for that is the ratio by which the dead outnumber the living. Since the dawn of time, roughly a hundred billion human beings have walked the planet Earth.

Now this is an interesting number, for by curious coincidence there are approximately a hundred billion stars in our local universe, the Milky Way. So for every man who has ever lived, in this Universe there shines a star.

[…] almost certainly there is enough land in the sky to give every member of the human species, back to the first ape-man, his own private, world-size heaven—or hell.

No point of this post, except that these lines really caught me. All four of Space Odyssey books have the eerie ability to cause shivers going down your spine.

2 responses so far

Oct 4 2007

Fényév távolság

Published by sld at 1:31 under Magyar and tagged ,

Voltunk ugye a Padlás című musicalen, de csak most néztem szét YouTube-on, és találtam egy kis ízelítőt azoknak, akik gondolkodnak a dolgon. A díszlet még mindig ugyanaz (a Vígszínházban készítették a felvételt).

In memoriam Kaszás Attila.

2 responses so far