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