Intro to Tests - raisercostin/software-wiki GitHub Wiki

General

Causes of Failed Tests

We investigate a failed test from the most probable cause to least probable

  • most probable
    • bug in new test input
    • bug in new test code
    • bug in new code
  • probable
    • bug in old test input
    • bug in old test code
    • bug in old code
  • improbable
    • bug in library
    • bug in Operating System
    • bug in firmware
    • bug in hardware

see also Test Driven Development

Notes

  • Do not comment tests add @Disabled(junit5), @Ignore(junit4)

QA

  1. What about testing the tests?

    https://softwareengineering.stackexchange.com/questions/11485/how-to-test-the-tests/11510#11510

Small Guide to JUnit

Tests

Type of tests

Libraries

Unit Tests

Good Tests

  • Should
    • be self contained:
      • in order to pass shouldn't be preceded by manual/automatic execution of other tests/main/tools.
      • have with them all necessary resources (probably in src/test/resources)
    • generate temporary files inside target\ folder to follow Intro to Maven conventions. See Convention over Configuration
  • Should not
    • have absolute paths - not portable between devs' environments
    • not contain complex code:

Integration Tests

  • Should not
    • delete existing data from repositories (databases, servers)
    • execute code that is never executed in production
  • Cleanup/Initialize before tests
    • The test must start from a known state (not necessary clean)
    • When test finish you want to manually inspect the state

Advanced

  • Tipuri de teste
    • regression tests - expected is recorded and later used as reference, good for legacy systems and systems with complex behaviour, ideal for e2e
    • e2e - end to end tests
    • whitebox testing
      • internal testing: depends on the internals of the application, based on a lot more assumptions, fragile testing (tests are broken when the internals are changed), the internals are changed more than the contract
    • blackbox testing
      • test against the surface (api/interface) that is a published contract
    • fragile testing
    • mock testing
      • mock tests are too fragile because they are used usually in a whitebox testing context
      • are more behaviour tests
    • behavioural testing
  • Testing bad practices
  • bad tests lead to no test at all
  • Who writes the tests?