All about testing code
Introduction to software testing
Åse L Mattson
Developer @ Skatteetaten
Trym Helle
Consultant at Dfind Consulting�trym.helle@dfind.no
WIFI
Network name: “uib-guest”
Follow the instructions after connecting to the network
New to Nerdschool?
Agenda
What is software testing?
What is software testing?
Why automate testing?
Automated testing
The testing hierarchy
Unit tests
Integration
tests
System
tests
Testing code
Writing test code - JUnit
Writing test code - Mockito
Test structure
Test structure
A larger “Given”-block
Writing good tests
What does a good test look like?
Naming
public void getFullName_whenLastNameIsEmpty_returnsFirstName() {� ...�}
DRY - Don’t Repeat Yourself
Strategies for DRY
Testing behavior, not implementation
Test-driven development
TDD - What
TDD - Why
TDD - Workflow
Exceptions, failures and errors
Exceptions in tests
@Test(expected = IllegalArgumentException.class)
public void someFancyTestThatThrowsAnException() {� ...�}
Failures vs. errors
Dependencies
Dependencies
public double calculateStudentLoanDebt() {� DebtRepository repository = new DebtRepository();� ...�}
Issues with dependencies
Dependency injection
Assignments
WIFI
Network name: “uib-guest”
Follow the instructions after connecting to the network
Assignments