Skip to main content

Reader: Testing Basics

Example reader for the demo course of Brightspacosaurus

1. Learning goals​

Download reader-testing-basics.pdf

📄 This reader is a PDF in Brightspace: download reader-testing-basics.pdf. Above is the PDF itself; below is the same text as a web page, easier to read on a phone and to search.

Learning goals:

  • Implement a small, well-tested pure function.
  • Explain the arrange-act-assert pattern.

A short reference on the arrange-act-assert pattern for unit tests.

2. Arrange-Act-Assert​

Most unit tests follow three phases:

  1. Arrange — set up the object under test and any inputs.
  2. Act — call the method being tested.
  3. Assert — verify the result matches expectations.

3. Test flow​

3. Test flow

Mermaid source for "3. Test flow"
flowchart TD
A[Arrange: create FizzBuzzer] --> B[Act: call fizzBuzz]
B --> C{Assert: result correct?}
C -->|yes| D[Test passes]
C -->|no| E[Test fails]
Natural language description not yet available for activity diagrams.

4. Class diagram​

4. Class diagram

PlantUML source for "4. Class diagram"
@startuml
class FizzBuzzer {
+fizzBuzz(n: int): String
}

class Main {
+main(args: String[]): void
}

Main ..> FizzBuzzer : uses
@enduml

Class diagram with 2 class(es) and 1 relation(s).

Classes:

  • Class FizzBuzzer with:
    • public method 'fizzBuzz', with parameter(s) 'n' of type int, return type String
    • no attributes
  • Class Main with:
    • public method 'main', with parameter(s) 'args' of type String[], return type void
    • no attributes

Relations:

  • Main has a dependency to FizzBuzzer

Keep tests small and focused: one behaviour per test, with a clear name that describes the expected outcome.