Package-level declarations

Tools for testing hurok-based applications

DSL for unit testing Action result

Functions for asserting Action results:

Example:

@Test
fun `Making a move works correctly`() {
// set up init model and expected model
// ...

initModel after OnMoveMade(position) matches {
assertModel(expectedModel)
assertNoEffects()
}
}

DSL for unit testing Effect

To test an Effect inherit from EffectTest and mock the dependency if there's one. Use com.ekezet.hurok.test.EffectTest.runWith to test and assert the subject against the mocked dependency.

Functions for asserting effect results:

  • com.ekezet.hurok.test.EmitAsserter.assertActions can be used to assert which actions were emitted

  • com.ekezet.hurok.test.EmitAsserter.assertNoActions can be used to assert that no actions ere emitted

Example:

class GameBoardEffectTest : EffectTest() {
// ...

@Test
fun `WaitBeforeNextTurn works correctly`() = runTest {
val nextMove: Position = mockk()

dependency runWith WaitBeforeNextTurn(nextMove) matches {
assertActions(listOf(OnMoveMade(nextMove)))
}
}
}

Testing the Renderer

To unit test a Renderer prepare a model, instantiate the Renderer and call its renderState() method to get the expected state. Then you can use assert methods like assertEquals() on the result.

Tools for testing hurok-based applications

DSL for unit testing Action result

Functions for asserting Action results:

Example:

@Test
fun `Making a move works correctly`() {
// set up init model and expected model
// ...

initModel after OnMoveMade(position) matches {
assertModel(expectedModel)
assertNoEffects()
}
}

DSL for unit testing Effect

To test an Effect inherit from EffectTest and mock the dependency if there's one. Use runWith to test and assert the subject against the mocked dependency.

Functions for asserting effect results:

Example:

class GameBoardEffectTest : EffectTest() {
// ...

@Test
fun `WaitBeforeNextTurn works correctly`() = runTest {
val nextMove: Position = mockk()

dependency runWith WaitBeforeNextTurn(nextMove) matches {
assertActions(listOf(OnMoveMade(nextMove)))
}
}
}

Testing the Renderer

To unit test a Renderer prepare a model, instantiate the Renderer and call its renderState() method to get the expected state. Then you can use assert methods like assertEquals() on the result.

Types

Link copied to clipboard
abstract class EffectTest(testContext: CoroutineContext = UnconfinedTestDispatcher(), testScope: CoroutineScope = TestScope(testContext)) : CoroutineScope

Base class for Effect tests.

Link copied to clipboard

Action emitter used for testing.

Link copied to clipboard

Asserter for action results.

Functions

Link copied to clipboard

Apply the action to a model.

Link copied to clipboard

Assert the result of an action.

infix inline fun <TModel : Any, TDependency> EmitAsserter<TModel, TDependency>.matches(crossinline block: EmitAsserter<TModel, TDependency>.() -> Unit)

Assert emitted actions by the Effect.