684aa60024c2876db0f74349ade59b426bf20981
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / shared / org / eclipse / linuxtools / tmf / core / tests / shared / DebugSuite.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.shared;
14
15 import org.junit.runner.notification.RunNotifier;
16 import org.junit.runners.Suite;
17 import org.junit.runners.model.InitializationError;
18
19 /**
20 * Test suite that adds a {@link DebugListener} to unit tests, to help debug
21 * misbehaving tests.
22 *
23 * Use with @RunWith(DebugSuite) and DebugSuite.SuiteClasses({ })
24 *
25 * @author Alexandre Montplaisir
26 */
27 public class DebugSuite extends Suite {
28
29 /**
30 * Constructor (required by JUnit)
31 *
32 * @param klass
33 * Root of the suite
34 * @throws InitializationError
35 * If an error happened when getting the test classes
36 */
37 public DebugSuite(Class<?> klass) throws InitializationError {
38 super(klass, getAnnotatedClasses(klass));
39 }
40
41 @Override
42 public void run(RunNotifier runNotifier) {
43 runNotifier.addListener(new DebugListener());
44 super.run(runNotifier);
45 }
46
47 private static Class<?>[] getAnnotatedClasses(Class<?> klass) throws InitializationError {
48 SuiteClasses annotation = klass.getAnnotation(SuiteClasses.class);
49 if (annotation == null) {
50 throw new InitializationError(String.format("class '%s' must have a SuiteClasses annotation", klass.getName()));
51 }
52 return annotation.value();
53 }
54 }
This page took 0.039905 seconds and 4 git commands to generate.