View Javadoc

1   /*
2    * Copyright 2011 Andres Gomez Casanova. All rights reserved.
3    *
4    * Redistribution and use in source and binary forms, with or without
5    * modification, are
6    * permitted provided that the following conditions are met:
7    *
8    * 1. Redistributions of source code must retain the above copyright notice,
9    * this list of conditions and the following disclaimer.
10   *
11   * 2. Redistributions in binary form must reproduce the above copyright notice,
12   * this list of conditions and the following disclaimer in the documentation
13   * and/or other materials provided with the distribution.
14   *
15   * THIS SOFTWARE IS PROVIDED BY Andres Gomez Casanova ``AS IS'' AND ANY EXPRESS
16   * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18   * EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24   *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25   *
26   *  The views and conclusions contained in the software and documentation are
27   *  those of the authors and should not be interpreted as representing official
28   *  policies, either expressed or implied, of Andres Gomez Casanova.
29   */
30  package net.sf.randomjunit;
31  
32  import java.util.Collections;
33  import java.util.List;
34  
35  import org.junit.runner.Runner;
36  import org.junit.runners.Suite;
37  import org.junit.runners.model.InitializationError;
38  import org.junit.runners.model.RunnerBuilder;
39  
40  /**
41   * This class randomize the execution of test suites.
42   * <p>
43   * Based on <a href=
44   * "http://stackoverflow.com/questions/1444314/how-can-i-make-my-junit-tests-run-in-random-order"
45   * >http://stackoverflow.com/questions/1444314/how-can-i-make-my-junit
46   * -tests-run-in-random-order</a>
47   * <p>
48   * <b>Control Version</b>
49   * <p>
50   * <ul>
51   * <li>1.0.0 Class creation.</li>
52   * </ul>
53   *
54   * @author Andres Gomez Casanova <a
55   *         href="mailto:a n g o c a at y a h o o dot c o m" >(AngocA)</a>
56   * @version 1.0.0 2011-06-13
57   */
58  public class RandomSuite extends Suite {
59  
60      /**
61       * Please see: {@link org.junit.runners.Suite#Suite(Class, RunnerBuilder)}.
62       *
63       * @param klass
64       *            the root class.
65       * @param builder
66       *            builds runners for classes in the suite
67       * @throws InitializationError
68       *             If any error.
69       */
70      public RandomSuite(Class<?> klass, RunnerBuilder builder)
71              throws InitializationError {
72          super(klass, builder);
73      }
74  
75      /**
76       * Please see: {@link org.junit.runners.Suite#Suite(RunnerBuilder, Class[])}
77       * .
78       *
79       * @param builder
80       *            builds runners for classes in the suite.
81       * @param classes
82       *            the classes in the suite.
83       * @throws InitializationError
84       *             If any error.
85       */
86      public RandomSuite(RunnerBuilder builder, Class<?>[] classes)
87              throws InitializationError {
88          super(builder, classes);
89      }
90  
91      /**
92       * @param klass
93       * @param runners
94       * @throws InitializationError
95       */
96      protected RandomSuite(Class<?> klass, List<Runner> runners)
97              throws InitializationError {
98          super(klass, runners);
99      }
100 
101     /*
102      * (non-Javadoc)
103      *
104      * @see org.junit.runners.Suite#getChildren()
105      */
106     @Override
107     protected List<Runner> getChildren() {
108         final List<Runner> children = super.getChildren();
109         Collections.shuffle(children);
110         return children;
111     }
112 
113 }