View Javadoc
1   package org.apache.maven.surefire.providerapi;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.lang.reflect.InvocationTargetException;
23  import org.apache.maven.surefire.report.ReporterException;
24  import org.apache.maven.surefire.suite.RunResult;
25  import org.apache.maven.surefire.testset.TestSetFailedException;
26  
27  /**
28   * Interface to be implemented by all Surefire providers.
29   * <br>
30   * NOTE: This class is part of the proposed public api for surefire providers for 2.7. It may
31   * still be subject to changes, even for minor revisions.
32   * <br>
33   * The api covers this interface and all the types reachable from it. And nothing else.
34   * <br>
35   * <br>
36   * Called in one of three ways:
37   * Forkmode = never: getSuites is not called, invoke is called with null parameter
38   * Forkmode = once: getSuites is not called, invoke is called with null parameter
39   * Forkmode anything else: getSuites is called, invoke is called on new provider instance for each item in getSuites
40   * response.
41   *
42   * @author Kristian Rosenvold
43   */
44  public interface SurefireProvider
45  {
46      /**
47       * Determines the number of forks.
48       * <br>
49       * Called when forkmode is different from "never" or "always", allows the provider to define
50       * how to behave for the fork.
51       *
52       * @return An iterator that will trigger one fork per item
53       */
54      Iterable<Class<?>> getSuites();
55  
56      /**
57       * Runs a forked test
58       *
59       * @param forkTestSet An item from the iterator in #getSuites. Will be null for forkmode never or always.
60       *                    When this is non-null, the forked process will run only that test
61       *                    and probably not scan the classpath
62       * @return A result of the invocation
63       * @throws org.apache.maven.surefire.report.ReporterException
64       *          When reporting fails
65       * @throws org.apache.maven.surefire.testset.TestSetFailedException
66       *          When testset fails
67       * @throws InvocationTargetException fails in {@code ProviderFactory}
68       */
69      @SuppressWarnings( "checkstyle:redundantthrows" )
70      RunResult invoke( Object forkTestSet )
71          throws TestSetFailedException, ReporterException, InvocationTargetException;
72  
73      /**
74       * Makes an attempt at cancelling the current run, giving the provider a chance to notify
75       * reporting that the remaining tests have been cancelled due to timeout.
76       * <br>
77       * If the provider thinks it can terminate properly it is the responsibility of
78       * the invoke method to return a RunResult with a booter code of failure.
79       * <br>
80       * It is up to the provider to find out how to implement this method properly.
81       * A provider may also choose to not do anything at all in this method,
82       * which means surefire will kill the forked process soon afterwards anyway.
83       * <br>
84       * Will be called on a different thread than the one calling invoke.
85       */
86      // Todo: Need to think a lot closer about how/if this works and if there is a use case for it.
87      // Killing a process is slightly non-deterministic
88      // And it
89      void cancel();
90  }