zio-bdd is a Behavior-Driven Development testing framework designed for Scala 3 applications using ZIO. It combines Gherkin-style feature files with ZIO's effect system to provide compile-time safety, fiber-based concurrency, and type-safe dependency injection, enhancing test expressiveness and reliability.
zio-bdd is an innovative Behavior-Driven Development (BDD) testing framework designed specifically for Scala 3 applications built on ZIO. By seamlessly integrating Gherkin-style feature files with ZIO’s effect system, this framework provides developers with enhanced compile-time safety, fiber-based concurrency, and type-safe dependency injection through ZLayer. This empowers teams to create clear, business-oriented tests that deliver robust error handling and modular service integration.
string, int, double, table[T]) for safe and easy parameter parsing, enhanced by ZIO Schema for complex data types.ScenarioContext for efficient test state management across multiple steps, facilitating seamless data sharing during tests.ZLayer to enable modular and type-safe dependency injection, streamlining the setup of test environments..feature files from a designated directory, with support for tag-based filtering to simplify test runs.PrettyReporter for console output and JUnit XML reporting, while allowing extensibility for custom output formats.Background, Scenario Outline, data tables, and tags (e.g., @ignore, @positive).A sample implementation for testing a greeting service illustrates how to define steps, manage state with ScenarioContext, and integrate ZIO services through a Gherkin feature file.
In example/src/test/scala/zio/bdd/example/GreetingSpec.scala, the domain model and service implementation are structured clearly:
// Domain and state
case class Context(userName: String, greeting: String)
object Context { implicit val schema: Schema[Context] = DeriveSchema.gen[Context] }
// Service
trait GreetingService { def greet(name: String): ZIO[Any, Nothing, String] }
case class GreetingServiceImpl(prefix: String) extends GreetingService {
def greet(name: String): ZIO[Any, Nothing, String] = ZIO.succeed(s"$prefix, $name!")
}
object GreetingService {
val live: ZLayer[String, Nothing, GreetingService] = ZLayer.fromFunction(GreetingServiceImpl(_))
}
The behaviors of the greetings are defined in a Gherkin feature file found at example/src/test/resources/features/greeting.feature:
@core @greeting
Feature: User Greeting
Scenario: Greet a positive user
Given a user named "Alice"
When the user is greeted
Then the greeting should be "Hello, Alice!"
@positive
Scenario: Greet another positive user
Given a user named "Bob"
When the user is greeted
Then the greeting should be "Hello, Bob!"
To ensure comprehensive testing:
sbt "example/test"
sbt "testOnly zio.bdd.example.GreetingSpec -- --include-tags positive"
sbt "testOnly zio.bdd.example.GreetingSpec -- --feature-file example/src/test/resources/features/greeting.feature"
sbt "example/testOnly zio.bdd.example.GreetingSpec -- -DlogLevel=debug"
Contributions: This open-source project welcomes contributions aimed at enhancing Gherkin support, reporting capabilities, or overall performance. Community involvement is encouraged through issues or pull requests on GitHub.
No comments yet.
Sign in to be the first to comment.