-
Notifications
You must be signed in to change notification settings - Fork 211
/
validate.sbt
46 lines (45 loc) · 2.03 KB
/
validate.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
lazy val validateUnitTestNames =
taskKey[Int]("Validate test naming convention for unit tests")
val inAllUnitTest = ScopeFilter(inAnyProject, inConfigurations(Test))
validateUnitTestNames := {
val testFileFullPath: Seq[Seq[String]] =
definedTestNames.all(inAllUnitTest).value
val log = streams.value.log
val invalidTestName = testFileFullPath
.flatMap(_.filterNot(_.endsWith("UnitTest")))
.filterNot(_.trim.isEmpty)
val invalidTestNameFormatted = invalidTestName.mkString("\n")
if (invalidTestName.nonEmpty) {
log.error(
s""" ***************************************************
|Found unit test classes not matching with naming standards. Unit test class must end with `UnitTest`.
|Refer to README.md file in the GitHub for more information.
|Invalid test classes:
|${invalidTestNameFormatted}
|***************************************************
|""".stripMargin
)
}
require(
invalidTestName.isEmpty,
s"Found ${invalidTestName.size} tests that doesn't follow naming convention, check the logs above for list of test classes!"
)
0
}
// for integration tests
//
//lazy val validateIntegrationTestNames = taskKey[Int]("Validate test naming convention for unit tests")
//val inAllIntegrationTest = ScopeFilter(inAnyProject, inConfigurations(IntegrationTest))
//validateIntegrationTestNames := {
// val testFileFullPath: Seq[Seq[String]] = definedTestNames.all(inAllIntegrationTest).value
// val log = streams.value.log
// val invalidTestName = testFileFullPath.flatMap(_.filterNot(_.endsWith("IntegrationTest"))).filterNot(_.trim.isEmpty)
// val invalidTestNameFormatted = invalidTestName.mkString("\n")
// log.error(
// s"""Found integration test files not matching with naming standards. Integration test files must end with IntegrationTest.scala.
// | Invalid files:
// | ${invalidTestNameFormatted}
// |""".stripMargin)
// require(invalidTestName.isEmpty, s"Found ${invalidTestName.size} tests that doesn't follow naming convention!")
// 0
//}