Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
XWikiExecutorTestMethodFilter | 56 | 7 | 0% | 5 | 10 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.test.integration; | |
21 | ||
22 | import org.junit.runner.Description; | |
23 | import org.junit.runner.manipulation.Filter; | |
24 | ||
25 | /** | |
26 | * Filter to be applied on {@link XWikiExecutorSuite}'s executed {@link org.junit.runner.Runner}s (i.e. test | |
27 | * classes). | |
28 | * <p> | |
29 | * Each child runner (i.e. test method) of a test class is compared with a {@link #pattern} to see if it | |
30 | * {@link #shouldRun(Description)} during this test execution. | |
31 | * <p> | |
32 | * The "pattern" System Property is a regex that gets applied to values such as: | |
33 | * <ul> | |
34 | * <li>pa.ck.a.ge.Class</li> | |
35 | * <li>pa.ck.a.ge.Class#method</li> | |
36 | * </ul> | |
37 | * <p> | |
38 | * Examples of valid patterns: | |
39 | * <dl> | |
40 | * <dt>-Dpattern="Test1" | |
41 | * <dd>run all tests from the matching test class(es) (that contain(s) "Test1" in its name) | |
42 | * <dt>-Dpattern="Test1|Test2" | |
43 | * <dd>run all tests from 2 test classes | |
44 | * <dt>-Dpattern="Test1#method1" | |
45 | * <dd>run just matching method(s) from matching test class(es) | |
46 | * <dt>-Dpattern="Test1#method1|Test2#method2" | |
47 | * <dd>run just matching methods from matching test classes (more than just 1 class) | |
48 | * <dt>-Dpattern="Test1#method1|Test2" | |
49 | * <dd>mix it; run just matching methods from the first matching class(es) and ALL tests from the second matching | |
50 | * class(es) | |
51 | * </dl> | |
52 | * | |
53 | * @version $Id: 4d7ad58e7e307a26fc14c0d4fdbc49511172b1d1 $ | |
54 | * @since 6.2 | |
55 | */ | |
56 | public class XWikiExecutorTestMethodFilter extends Filter | |
57 | { | |
58 | protected String pattern; | |
59 | ||
60 | /** | |
61 | * Constructor. | |
62 | * | |
63 | * @param pattern the pattern to use when filtering a runner's children (i.e. test methods). | |
64 | */ | |
65 | 18 | public XWikiExecutorTestMethodFilter(String pattern) |
66 | { | |
67 | 18 | this.pattern = pattern; |
68 | } | |
69 | ||
70 | /** | |
71 | * @return the pattern to use when filtering a {@link org.junit.runner.Runner}'s children (i.e. test methods). | |
72 | */ | |
73 | 0 | public String getPattern() |
74 | { | |
75 | 0 | return pattern; |
76 | } | |
77 | ||
78 | /** | |
79 | * @param pattern the new pattern to use. | |
80 | */ | |
81 | 0 | public void setPattern(String pattern) |
82 | { | |
83 | 0 | this.pattern = pattern; |
84 | } | |
85 | ||
86 | 0 | @Override |
87 | public boolean shouldRun(Description description) | |
88 | { | |
89 | 0 | String testMethodName = String.format("%s#%s", description.getClassName(), description.getMethodName()); |
90 | 0 | boolean result = testMethodName.matches(this.pattern); |
91 | ||
92 | 0 | return result; |
93 | } | |
94 | ||
95 | 0 | @Override |
96 | public String describe() | |
97 | { | |
98 | 0 | return "Run only the tests specified with the -Dpattern parameter."; |
99 | } | |
100 | } |