Testing

Testing in Norscode becomes much easier when logic is divided into small functions and clear boundaries. Tests are not only for catching bugs. They are also a way to preserve intent while a project evolves.

Start small

Early tests should focus on pure logic: functions that validate, calculate or transform. These tests are cheap to write and often provide the clearest signal when behaviour changes unexpectedly.

test "rabatt skal senke pris" {
    la pris: heltall = rabatt(1000, 20)
    assert_eq(pris, 800, "Rabattlogikk feil")
}

Test boundaries on purpose

As the project grows, add tests around handlers, contracts and error responses. Those tests matter because regressions often appear at boundaries between layers: route parsing, JSON shape, storage rules or integration failure behaviour.

The natural follow-up chapters are functions, contracts and web and API.