cats.effect.kernel.testkit

Type members

Classlikes

trait AsyncGenerators[F[_]] extends GenTemporalGenerators[F, Throwable] with SyncGenerators[F]
trait ClockGenerators[F[_]] extends Generators1[F]
trait GenK[F[_]] extends Serializable
trait Generators1[F[_]] extends Serializable
trait SyncGenerators[F[_]] extends MonadErrorGenerators[F, Throwable] with ClockGenerators[F]
final class TestContext extends ExecutionContext

A scala.concurrent.ExecutionContext implementation that can simulate async boundaries and time passage, useful for law testing purposes. This is intended primarily for datatype implementors. Most end-users will be better served by the cats.effect.testkit.TestControl utility, rather than using TestContext directly.

A scala.concurrent.ExecutionContext implementation that can simulate async boundaries and time passage, useful for law testing purposes. This is intended primarily for datatype implementors. Most end-users will be better served by the cats.effect.testkit.TestControl utility, rather than using TestContext directly.

Usage for simulating an ExecutionContext):

 implicit val ec = TestContext()

 ec.execute(new Runnable { def run() = println("task1") })

 ex.execute(new Runnable {
   def run() = {
     println("outer")

     ec.execute(new Runnable {
       def run() = println("inner")
     })
   }
 })

 // Nothing executes until `tick` gets called
 ec.tick()

 // Testing the resulting state
 assert(ec.state.tasks.isEmpty)
 assert(ec.state.lastReportedFailure == None)
Companion:
object
Source:
TestContext.scala
Companion:
class
Source:
TestContext.scala
final case class TestException(i: Int) extends Exception
object freeEval extends FreeSyncEq
object pure
Source:
pure.scala