Skip to content

Commit ce27ce0

Browse files
committed
Validation for unit test names
1 parent 3f7457c commit ce27ce0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

validate.sbt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
lazy val validateTestNames = taskKey[Int]("Validate test naming convention")
2+
val inAllTest = ScopeFilter(inAnyProject, inConfigurations(Test))
3+
validateTestNames := {
4+
val testFileFullPath: Seq[Seq[String]] = definedTestNames.all(inAllTest).value
5+
val log = streams.value.log
6+
val invalidTestName = testFileFullPath.flatMap(_.filterNot(_.endsWith("UnitTest")))
7+
val invalidTestNameFormatted = invalidTestName.mkString("\n")
8+
log.error(
9+
s"""Found unit test files not matching with naming standards. Unit test files must end with UnitTest.scala.
10+
| Invalid files:
11+
| ${invalidTestNameFormatted}
12+
|""".stripMargin)
13+
require(invalidTestName.isEmpty, s"Found ${invalidTestName.size} tests that doesn't follow naming convention!")
14+
0
15+
}

0 commit comments

Comments
 (0)