16
16
*/
17
17
package org .scalatestplus .junit
18
18
19
- import org .scalatest ._
19
+ import org .scalatest .{ Args , ConfigMap , DynaTags , Stopper , Suite , Tracker , Filter }
20
20
import org .junit .runner .notification .RunNotifier
21
21
import org .junit .runner .notification .Failure
22
22
import org .junit .runner .Description
23
23
import org .junit .runner .manipulation .{Filter => TestFilter , Filterable , NoTestsRemainException }
24
24
25
+ import scala .collection .JavaConverters ._
26
+ import scala .collection .mutable
27
+
25
28
/*
26
29
I think that Stopper really should be a no-op, like it is, because the user has
27
30
no way to stop it. This is wierd, because it will call nested suites. So the tests
@@ -71,6 +74,8 @@ final class JUnitRunner(suiteClass: java.lang.Class[_ <: Suite]) extends org.jun
71
74
*/
72
75
val getDescription = createDescription(suiteToRun)
73
76
77
+ private val excludedTests : mutable.Set [String ] = mutable.Set ()
78
+
74
79
private def createDescription (suite : Suite ): Description = {
75
80
val description = Description .createSuiteDescription(suite.getClass)
76
81
// If we don't add the testNames and nested suites in, we get
@@ -96,12 +101,29 @@ final class JUnitRunner(suiteClass: java.lang.Class[_ <: Suite]) extends org.jun
96
101
*/
97
102
def run (notifier : RunNotifier ): Unit = {
98
103
try {
104
+ val includedTests : Set [String ] = suiteToRun.testNames.diff(excludedTests)
105
+ val testTags : Map [String , Map [String , Set [String ]]] = Map (
106
+ suiteToRun.suiteId ->
107
+ includedTests.map(test => test -> Set (" INCLUDE" )).toMap
108
+ )
109
+ val filter = Filter (
110
+ tagsToInclude = Some (Set (" INCLUDE" )),
111
+ dynaTags = DynaTags (suiteTags = Map .empty, testTags = testTags)
112
+ )
99
113
// TODO: What should this Tracker be?
100
- suiteToRun.run(None , Args (new RunNotifierReporter (notifier),
101
- Stopper .default, Filter (), ConfigMap .empty, None ,
102
- new Tracker ))
103
- }
104
- catch {
114
+ suiteToRun.run(
115
+ None ,
116
+ Args (
117
+ new RunNotifierReporter (notifier),
118
+ Stopper .default,
119
+ filter,
120
+ ConfigMap .empty,
121
+ None ,
122
+ new Tracker ,
123
+ Set .empty
124
+ )
125
+ )
126
+ } catch {
105
127
case e : Exception =>
106
128
notifier.fireTestFailure(new Failure (getDescription, e))
107
129
}
@@ -113,10 +135,16 @@ final class JUnitRunner(suiteClass: java.lang.Class[_ <: Suite]) extends org.jun
113
135
*
114
136
* @return the expected number of tests that will run when this suite is run
115
137
*/
116
- override def testCount () = suiteToRun.expectedTestCount(Filter ())
138
+ override def testCount (): Int = suiteToRun.expectedTestCount(Filter ())
117
139
140
+ @ throws(classOf [NoTestsRemainException ])
118
141
override def filter (filter : TestFilter ): Unit = {
119
- if (! filter.shouldRun(getDescription)) throw new NoTestsRemainException
142
+ getDescription.getChildren.asScala
143
+ .filter(child => ! filter.shouldRun(child))
144
+ .foreach(child => excludedTests.add(child.getMethodName))
145
+ if (getDescription.getChildren.isEmpty) {
146
+ throw new NoTestsRemainException ()
147
+ }
120
148
}
121
149
122
150
}
0 commit comments