plugins {
id "com.github.maiflai.scalatest" version "0.12"
}
ScalaTest
Gradle, ScalaTest
Run only tagged tests
There is a plugin to enable the use of scala tests in a gradle project.
Define a tag as scala object. With tags we will include or exclude some tests from execution.
Create a scala file zeromq.Tags.scala
package zeromq
import org.scalatest.Tag
object Ip2LocTest extends Tag("Ip2LocTest")
Add tag Ip2LocTest
to the tests.
package zeromq
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
import org.zeromq.ZMQ
@RunWith(classOf[JUnitRunner])
class Ip2LocEnricherSpec extends FlatSpec {
"Enricher" should "get location for ip" taggedAs (Ip2LocTest) in {
val enricher = Ip2LocEnricher(Ip2LocConfig(ZeroMQServerMock.CLT_ADR).copy(sendTimeout = 5000))
val server = new ZeroMQServerMock().oneTimeAnswer {req =>
// ... conversion in Array[Byte] to object, enrichment, and Array[Byte] as output
}
val resp = enricher.enrich("127.0.0.1")
assert(resp != null)
}
}
Then in gradle.build
file add configuration of tags to test
task.
test {
tags {
include "Ip2LocTest"
}
}
Run tests. Only tests tagged with Ip2LocTest
will be executed.
$ ./gradle test
Sample output
Run completed in 1 second, 674 milliseconds. Total number of tests run: 1 Suites: completed 4, aborted 0 Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0 All tests passed.