-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add junit 5 engine for zio tests. Resolves zio/zio#6724 #9214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>dev.zio</groupId> | ||
<version>1.0</version> | ||
<artifactId>zio_test_junit_engine_test</artifactId> | ||
<packaging>pom</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>Testing ZIO Test Junit engine test project</description> | ||
<inceptionYear>2024</inceptionYear> | ||
|
||
<properties> | ||
<encoding>UTF-8</encoding> | ||
<scala.version>2.13.13</scala.version> | ||
<scala.compat.version>2.12</scala.compat.version> | ||
<zio.version>2.0.22</zio.version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for using version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't matter, it's overwritten by the test with the current version. This is only a template. The concept was taken from "test-junit-tests". The idea is the same as this project: we run simple tests with maven to check that the engine picks them and reports them correctly | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.11.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>dev.zio</groupId> | ||
<artifactId>zio-test_${scala.compat.version}</artifactId> | ||
<version>${zio.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>dev.zio</groupId> | ||
<artifactId>zio_${scala.compat.version}</artifactId> | ||
<version>${zio.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>dev.zio</groupId> | ||
<artifactId>zio-test-junit-engine_${scala.compat.version}</artifactId> | ||
<version>${zio.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.5.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>scala2</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.scala-lang</groupId> | ||
<artifactId>scala-library</artifactId> | ||
<version>${scala.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
<profile> | ||
<id>scala3</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.scala-lang</groupId> | ||
<artifactId>scala3-library_${scala.compat.version}</artifactId> | ||
<version>${scala.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
</profiles> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<!-- see http://davidb.github.com/scala-maven-plugin --> | ||
<groupId>net.alchim31.maven</groupId> | ||
<artifactId>scala-maven-plugin</artifactId> | ||
<version>4.8.1</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
<goal>testCompile</goal> | ||
</goals> | ||
<configuration> | ||
<args> | ||
<!--<arg>-make:transitive</arg>--> | ||
<arg>-dependencyfile</arg> | ||
<arg>${project.build.directory}/.scala_dependencies</arg> | ||
<arg>-Ywarn-value-discard</arg> | ||
</args> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.2.5</version> | ||
<configuration> | ||
<goal>test</goal> | ||
<parallel>methods</parallel> | ||
<threadCount>10</threadCount> | ||
<includes> | ||
<include>**/*Spec.*</include> | ||
</includes> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
</project> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
|
||
</settings> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package zio.test.junit.maven | ||
|
||
import zio.test.Assertion.equalTo | ||
import zio.test.{Spec, TestEnvironment, assert, ZIOSpecDefault} | ||
import zio.{Scope, Task, ZIO, ZLayer} | ||
|
||
trait Ops { | ||
def targetHost: String | ||
} | ||
|
||
object OpsTest extends Ops { | ||
override def targetHost: String = null | ||
} | ||
|
||
trait MyService { | ||
def readData : Task[List[String]] | ||
} | ||
|
||
class MyServiceTest(targetHostName: String) extends MyService { | ||
|
||
val url = s"https://${targetHostName.toLowerCase}/ws" // <- null pointer exception here | ||
|
||
override def readData: Task[List[String]] = { | ||
ZIO.succeed(List("a","b")) | ||
} | ||
} | ||
|
||
object DefectSpec extends ZIOSpecDefault { | ||
override def spec: Spec[TestEnvironment with Scope, Any] = suite("nul test")( | ||
test("test with defect") { | ||
for { | ||
ms <- ZIO.service[MyService] | ||
result <- ms.readData | ||
} | ||
yield assert(result.size)(equalTo(2)) | ||
}.provideLayer(ZLayer.succeed(new MyServiceTest(OpsTest.targetHost))) | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package zio.test.junit.maven | ||
|
||
import zio.test.junit._ | ||
import zio.test._ | ||
import zio.test.Assertion._ | ||
|
||
object FailingSpec extends ZIOSpecDefault { | ||
override def spec = suite("FailingSpec")( | ||
test("should fail") { | ||
assert(11)(equalTo(12)) | ||
}, | ||
test("should fail - isSome") { | ||
assert(Some(11))(isSome(equalTo(12))) | ||
}, | ||
test("should succeed") { | ||
assert(12)(equalTo(12)) | ||
} | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale behind creating a new module instead of updating the existing one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different. Test-junit implements a JUnit 4 Runner that allows "junit-vintage" engine (compatibility layer to run JUnit 3 and 4 tests with the JUnit 5 platform) to discover the tests that extend this class. In this case, it's a new JUnit test engine able to discover by itself the ZIO tests