001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.runtime.test.runner;
020
021import org.junit.runners.model.FrameworkMethod;
022
023import com.google.inject.Binder;
024
025/**
026 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
027 */
028public interface RunnerFeature {
029
030    /**
031     * Called when preparing to run the test class. Framework is not started at this point. Here is time for the feature
032     * to configure the runner from annotations on the test class.
033     */
034    void initialize(FeaturesRunner runner) throws Exception;
035
036    /**
037     * Configures Guice bindings if any is required by the feature. This is called after the framework is started and
038     * before Guice module is built. The tests are launched after guice module is built.
039     */
040    void configure(FeaturesRunner runner, Binder binder);
041
042    /**
043     * Before running tests. At this point Guice modules are registered and injector created.
044     */
045    void beforeRun(FeaturesRunner runner) throws Exception;
046
047    /**
048     * After tests were run.
049     */
050    void afterRun(FeaturesRunner runner) throws Exception;
051
052    /**
053     * Features are initialized. Runner is ready to create the injector.
054     */
055    void start(FeaturesRunner runner) throws Exception;
056
057    /**
058     * Notification that a test instance was created. Can be used by features to make custom injection or other
059     * preparation of the test instance.
060     *
061     * @param test
062     * @throws Exception
063     */
064    void testCreated(Object test) throws Exception;
065
066    /**
067     * Before exiting the test.
068     */
069    void stop(FeaturesRunner runner) throws Exception;
070
071    /**
072     * Before entering in the @Before methods
073     *
074     * @param runner
075     */
076    void beforeSetup(FeaturesRunner runner) throws Exception;
077
078    /**
079     * After the call of the @After methods
080     *
081     * @param runner
082     */
083    void afterTeardown(FeaturesRunner runner) throws Exception;
084
085    /**
086     * Before a test method is invoked.
087     */
088    void beforeMethodRun(FeaturesRunner runner, FrameworkMethod method, Object test) throws Exception;
089
090    /**
091     * After a test method was ran.
092     */
093    void afterMethodRun(FeaturesRunner runner, FrameworkMethod method, Object test) throws Exception;
094
095}