org.unitils
Class UnitilsJUnit4TestClassRunner

java.lang.Object
  extended by org.junit.runner.Runner
      extended by org.junit.internal.runners.JUnit4ClassRunner
          extended by org.unitils.UnitilsJUnit4TestClassRunner
All Implemented Interfaces:
org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Sortable

public class UnitilsJUnit4TestClassRunner
extends org.junit.internal.runners.JUnit4ClassRunner

Custom test runner that will Unitils-enable your test. This will make sure that the core unitils test listener methods are invoked in the expected order. See TestListener for more information on the listener invocation order.

NOTE: if a test fails, the error is logged as debug logging. This is a temporary work-around for a problem with IntelliJ JUnit-4 runner that reports a 'Wrong test finished' error when something went wrong in the before. [IDEA-12498]

Author:
Tim Ducheyne, Filip Neven

Nested Class Summary
protected  class UnitilsJUnit4TestClassRunner.TestListenerInvokingMethodRoadie
          Custom method roadie that invokes the unitils test listener methods at the apropriate moments.
 
Constructor Summary
UnitilsJUnit4TestClassRunner(Class<?> testClass)
          Creates a test runner that runs all test methods in the given class.
 
Method Summary
protected  org.junit.internal.runners.MethodRoadie createMethodRoadie(Object testObject, Method testMethod, org.junit.internal.runners.TestMethod jUnitTestMethod, org.junit.runner.notification.RunNotifier notifier, org.junit.runner.Description description)
          Returns the JUnit 4 MethodRoadie object that is used to execute the test method
protected  TestListener getTestListener()
           
protected  Unitils getUnitils()
          Returns the default singleton instance of Unitils
protected  void invokeTestMethod(Method method, org.junit.runner.notification.RunNotifier notifier)
          Overridden JUnit4 method to be able to create a CustomMethodRoadie that will invoke the unitils test listener methods at the appropriate moments.
 void run(org.junit.runner.notification.RunNotifier notifier)
           
 
Methods inherited from class org.junit.internal.runners.JUnit4ClassRunner
classAnnotations, createTest, filter, getDescription, getName, getTestClass, getTestMethods, methodDescription, runMethods, sort, testAnnotations, testName, validate, wrapMethod
 
Methods inherited from class org.junit.runner.Runner
testCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnitilsJUnit4TestClassRunner

public UnitilsJUnit4TestClassRunner(Class<?> testClass)
                             throws org.junit.internal.runners.InitializationError
Creates a test runner that runs all test methods in the given class.

Parameters:
testClass - the class, not null
Throws:
org.junit.internal.runners.InitializationError
Method Detail

run

public void run(org.junit.runner.notification.RunNotifier notifier)
Overrides:
run in class org.junit.internal.runners.JUnit4ClassRunner

invokeTestMethod

protected void invokeTestMethod(Method method,
                                org.junit.runner.notification.RunNotifier notifier)
Overridden JUnit4 method to be able to create a CustomMethodRoadie that will invoke the unitils test listener methods at the appropriate moments.

Overrides:
invokeTestMethod in class org.junit.internal.runners.JUnit4ClassRunner

createMethodRoadie

protected org.junit.internal.runners.MethodRoadie createMethodRoadie(Object testObject,
                                                                     Method testMethod,
                                                                     org.junit.internal.runners.TestMethod jUnitTestMethod,
                                                                     org.junit.runner.notification.RunNotifier notifier,
                                                                     org.junit.runner.Description description)
Returns the JUnit 4 MethodRoadie object that is used to execute the test method

Parameters:
testObject - The test instance, not null
testMethod - The test method, not null
jUnitTestMethod - The JUnit test method
notifier - The run listener, not null
description - A test description
Returns:
An JUnit MethodRoadie

getTestListener

protected TestListener getTestListener()
Returns:
The unitils test listener

getUnitils

protected Unitils getUnitils()
Returns the default singleton instance of Unitils

Returns:
the Unitils instance, not null


Copyright © 2011. All Rights Reserved.