Questions tagged [zio-test]

ZIO Test is a zero dependency testing library that makes it easy to test effectual programs.

See here for more informations here: https://zio.dev/docs/usecases/usecases_testing

29 questions
11
votes
7 answers

How to test an exception case with zio-test

I have the following function, that I want to test: def people(id: Int): RIO[R, People] This function returns People if there is one for that id, resp. fails if not, like: IO.fail(ServiceException(s"No People with id $id")) The happy case works,…
pme
  • 14,156
  • 3
  • 52
  • 95
7
votes
1 answer

How to enforce to run ZIO Tests sequentially

I want to run two integration tests sequentially. How can this be achieved in ZIO Test? Here is the Suite: suite("Undeploy a Package")( testM("There is a Package") { PackageDeployer.deploy(pckg) *> // first deploy …
pme
  • 14,156
  • 3
  • 52
  • 95
6
votes
1 answer

Is there a way to add a descriptive Assert message in a Boolean ZIO Test

I have a couple of Booleans I want to test, like assert(g8Exists, equalTo(true)) && assert(projectExists, equalTo(true)) && assert(testenvExists, equalTo(true)) ... If one fails, all I get is: false did not satisfy equalTo(true) No clue which line…
pme
  • 14,156
  • 3
  • 52
  • 95
4
votes
2 answers

How do I assert that an Option contains something in zio-test?

I tried assert(anOption)(contains("x")) But that only works for Iterables such as List or Seq.
Thilo
  • 257,207
  • 101
  • 511
  • 656
4
votes
1 answer

How to ignore a Suite or a Test in ZIO Test?

I could not find anything on how to ignore a Suite or a Test with ZIO Test. Whether in an example nor in the documentation (https://zio.dev/docs/usecases/usecases_testing) There is an ignored in the test package object: /** * Creates an ignored…
pme
  • 14,156
  • 3
  • 52
  • 95
2
votes
1 answer

How do I suppress or redirect (e.g. to a file) Testcontainer output in Testcontainers Scala with ZIO Test?

I am using ZIO 2 and ZIO Test with plain testcontainers-scala. The test looks like this: object MongoRepositorySpec extends ZIOSpecDefault: object TestLayers: val mongoTestcontainer: ZLayer[Any, Throwable, MongoDBContainer] = …
Chris W.
  • 2,266
  • 20
  • 40
2
votes
2 answers

How does one assert a single field in error type?

Let's assume I have code such as this: final case class CustomException(errorCode: Int, id: UUID) extends Throwable val logic: ZIO[Any, Throwable, Unit] = ??? I would like to use ZIO Test to check for a specific error case val checkForTimeout =…
1
vote
1 answer

ZioHttp end point - Return json response

I am creating a ZioHttp Rest endpoint... For a Json request I want to return Json response ... I'm able to retrun logs, print lines but not sure how to return json response... Here's my code: import zio.{Console, _} import zhttp._ import…
1
vote
1 answer

Integration tests hangs when testing my API in ZIO + HTTP4S

I am having issues testing my first ZIO+HTTP4S application. The test hangs and does not finish. The code for my App (simplified) is object Main extends App { def server: ZIO[AppEnvironment, Throwable, Unit] = for { (...) fullApp…
1
vote
1 answer

ZIO Mock method that works with generics

I'm trying to mock a service that has a generic method but I can't figure out how to define the effect in the mock. Can a generic effect even work? Are there any workarounds? The service: object AService { type AService = Has[Service] trait…
Tudor
  • 103
  • 1
  • 1
  • 5
1
vote
0 answers

Share managed resources in tests (zio tests)

I'm binding an HttpRoute and testing it. That occurs inside a ZManaged context. Yet I need to use it for each test, which is very resource inefficient. Is there a way run many labeled tests inside a ZManaged context?
caeus
  • 3,084
  • 1
  • 22
  • 36
1
vote
0 answers

Mocking a Function with empty parameter list in ZIO Test

I have the following function I want to mock: def deployments(): Task[Seq[Deployment]] My envBuilder looks like: ZLayer.fromService(invoke => new processEngineService.Service { def deployments(): Task[Seq[Deployment]] = …
pme
  • 14,156
  • 3
  • 52
  • 95
1
vote
1 answer

Mocking any value as input parameter with ZIO Test

I mock the following function: def deploy(deployRequest: DeployRequest, mergeResults: Seq[MergeResult]): Task[Deployment] For the result I don't care for the inputs. So my question, is there a Way to achieve this with zio.test.mock. Something…
pme
  • 14,156
  • 3
  • 52
  • 95
1
vote
1 answer

'A test is using time, but is not advancing the test clock' in ZIO Test

After migrating my Test to RC18, I get the following warning and the test is hanging: Warning: A test is using time, but is not advancing the test clock, which may result in the test hanging. Use TestClock.adjust to manually advance the time. I…
pme
  • 14,156
  • 3
  • 52
  • 95
1
vote
1 answer

How to correctly verify scheduled invocations in ZIO Test

I am new to ZIO and ZIO Test and I'd like to test a scheduling service I wrote under ZIO v1.0.0RC17: The service(s): import zio.{RIO, Schedule} import zio.clock.Clock import zio.duration._ trait ModuleA { def moduleA: ModuleA.Service } object…
imRentable
  • 45
  • 5
1
2