-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from kpodsiad/test-selector
Take into account `TaskDef`s with `TestSelector`s
- Loading branch information
Showing
8 changed files
with
173 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ target | |
/\.manager/ | ||
/\.idea/ | ||
/\.idea_modules/ | ||
.metals/ | ||
.bloop/ | ||
.bsp/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name := "test-project" | ||
|
||
scalaVersion := "2.13.7" | ||
|
||
libraryDependencies += "com.github.sbt" % "junit-interface" % sys.props("plugin.version") % "test" | ||
libraryDependencies += "org.scala-sbt" % "test-agent" % "1.5.5" % Test |
1 change: 1 addition & 0 deletions
1
src/sbt-test/simple/check-test-selector/project/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.6.1 |
102 changes: 102 additions & 0 deletions
102
src/sbt-test/simple/check-test-selector/src/test/scala/CheckTestSelector.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import com.novocode.junit.JUnitFramework | ||
import com.novocode.junit.JUnitFingerprint | ||
|
||
import org.junit.Test | ||
import org.junit.Assert._ | ||
|
||
import sbt.testing._ | ||
import scala.collection.mutable.ArrayBuffer | ||
|
||
/** | ||
* Check if TestSelector's are correctly handled by JUnitRunner. | ||
* Execute prepared TaskDef's using manually created instances of sbt.testing.{Framework and Runner}. | ||
*/ | ||
class CheckTestSelector { | ||
val framework = new JUnitFramework(); | ||
val runner = framework.runner( | ||
Array.empty[String], | ||
Array.empty[String], | ||
this.getClass().getClassLoader() | ||
); | ||
|
||
private def getEventHandler(): (ArrayBuffer[String], EventHandler) = { | ||
val executedItems = new scala.collection.mutable.ArrayBuffer[String] | ||
val eventHandler = new EventHandler { | ||
override def handle(event: Event) = | ||
if (event.status() == Status.Success) { | ||
executedItems.addOne(event.fullyQualifiedName()) | ||
} | ||
} | ||
(executedItems, eventHandler) | ||
} | ||
|
||
private def getTaskDefs(selectors: Array[Selector]): Array[TaskDef] = { | ||
Array( | ||
new TaskDef("a.b.MyTestSuite", new JUnitFingerprint(), false, selectors) | ||
) | ||
} | ||
|
||
@Test | ||
def runAllViaSuiteSelector() { | ||
val selectors = Array[Selector]( | ||
new SuiteSelector | ||
) | ||
val taskDefs = Array( | ||
new TaskDef("a.b.MyTestSuite", new JUnitFingerprint(), false, selectors) | ||
) | ||
|
||
val tasks = runner.tasks(taskDefs) | ||
assertEquals(tasks.size, 1) | ||
val task = tasks(0) | ||
|
||
val (executedItems, eventHandler) = getEventHandler() | ||
|
||
task.execute(eventHandler, Nil.toArray) | ||
assertArrayEquals( | ||
Array[Object]("a.b.MyTestSuite.testBar", "a.b.MyTestSuite.testFoo"), | ||
executedItems.toArray[Object] | ||
) | ||
} | ||
|
||
@Test | ||
def runAllViaTestSelectors() { | ||
val selectors = Array[Selector]( | ||
new TestSelector("testFoo"), | ||
new TestSelector("testBar") | ||
) | ||
val taskDefs = getTaskDefs(selectors) | ||
|
||
val tasks = runner.tasks(taskDefs) | ||
assertEquals(tasks.size, 1) | ||
val task = tasks(0) | ||
|
||
val (executedItems, eventHandler) = getEventHandler() | ||
|
||
task.execute(eventHandler, Nil.toArray) | ||
assertArrayEquals( | ||
Array[Object]("a.b.MyTestSuite.testBar", "a.b.MyTestSuite.testFoo"), | ||
executedItems.toArray[Object] | ||
) | ||
} | ||
|
||
@Test | ||
def runOnlyOne() { | ||
val selectors = Array[Selector]( | ||
new TestSelector("testFoo") | ||
) | ||
val taskDefs = getTaskDefs(selectors) | ||
|
||
val tasks = runner.tasks(taskDefs) | ||
assertEquals(tasks.size, 1) | ||
val task = tasks(0) | ||
|
||
val (executedItems, eventHandler) = getEventHandler() | ||
|
||
task.execute(eventHandler, Nil.toArray) | ||
assertArrayEquals( | ||
Array[Object]("a.b.MyTestSuite.testFoo"), | ||
executedItems.toArray[Object] | ||
) | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/sbt-test/simple/check-test-selector/src/test/scala/a/b/MyTestSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package a.b | ||
|
||
import org.junit.Test | ||
import org.junit.Assert.assertEquals | ||
|
||
class MyTestSuite { | ||
|
||
@Test | ||
def testFoo(): Unit = { | ||
assertEquals("Test should pass", true, true) | ||
} | ||
|
||
@Test | ||
def testBar(): Unit = { | ||
assertEquals("Test should pass", true, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# make sure the unit test passes | ||
> test |