KEMBAR78
3 - Software Testing Testing Levels | PDF | Test Driven Development | Unit Testing
0% found this document useful (0 votes)
16 views49 pages

3 - Software Testing Testing Levels

The document outlines a course on software testing, focusing on unit testing, integration testing, end-to-end testing, and Test Driven Development (TDD). It emphasizes the importance of writing effective tests to maintain code quality and reduce software entropy. The course aims to equip participants with the skills to write various types of tests and understand testing methodologies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views49 pages

3 - Software Testing Testing Levels

The document outlines a course on software testing, focusing on unit testing, integration testing, end-to-end testing, and Test Driven Development (TDD). It emphasizes the importance of writing effective tests to maintain code quality and reduce software entropy. The course aims to equip participants with the skills to write various types of tests and understand testing methodologies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Software Testing :

Testing Levels

Régis ATEMENGUE
Software Engineer | Technical Instructor.
@regis_ate | www.regisatemengue.com
Course Objectives
Understand the purpose of unit testing, integration
testing, and end-to-end testing

Understand the TDD approach

Write your first unit, integration and end-to-end


testing

Write good tests cases

@regis_ate | www.regisatemengue.com
2
Course overview
Unit Testing

Integration Testing

End to End Testing

TDD: Test Driven Development

@regis_ate | www.regisatemengue.com
33
Software Testing: Testing Levels

Testing is an important part of any software


project. Learning unit, integration or end-to-end
testing isn't just about using test libraries.

You can write tests for your project. But code


quality isn't always good, and then your
application breaks and still requires a lot of
maintenance.
It's important to find the balance between writing
tests and maximizing the benefits of testing in
your project.

@regis_ate | www.regisatemengue.com 74
Unit Testing

Big Picture

Terminologies

Anatomie of Unit Testing

Test Double

Demo: Unit Testing

@regis_ate | www.regisatemengue.com
55
Unit Testing: Big Picture

@regis_ate | www.regisatemengue.com
6
Unit Testing

What’s a unit testing ?


There are many definitions of a unit test. The definitions all have the following three most
important attributes.

A unit test is an automated test that:

Checks a small piece of code (also called a unit),


does it quickly,
And does so in isolation.

@regis_ate | www.regisatemengue.com 7
Unit Testing
What’s a unit testing ?

@regis_ate | www.regisatemengue.com 8
Unit Testing
Current state of Unit Testing
Over the past two decades, many companies have adopted unit testing. Unit testing is now considered
mandatory in most companies.

In enterprise application development, almost every project includes at least some unit testing.

In an enterprise, unit testing is mandatory unless you're working on a useless project.

Unit testing continues to evolve, and so do technologies. Since testing is an important part of software
systems. The discussion shifted from “Should we write unit tests” to “What does it mean to write
good unit tests”.

@regis_ate | www.regisatemengue.com 9
Terminologies

@regis_ate | www.regisatemengue.com
10
Unit Testing
Useful terminology.

Test case: a set of inputs, execution conditions, and pass/fail criteria.

Test case specification: requirement to be met by one or more test cases.

Test suit: a set of test cases.

SUT: (System Under Test):

A method under test (MUT): is a method of the SUT called up by the test. The terms MUT and SUT are
often used synonymously, but normally MUT refers to a method while SUT refers to the entire class.

@regis_ate | www.regisatemengue.com 11
Unit Testing
Test Case

@regis_ate | www.regisatemengue.com 12
Unit Testing
Test Case

@regis_ate | www.regisatemengue.com 13
Unit Testing
SUT /MUT

@regis_ate | www.regisatemengue.com 14
Unit Testing
Unit test objectives
Software Entropy

In software, entropy manifests itself in the form of code that tends to deteriorate. Every time
you change something in a code, the amount of disorder it contains, or entropy, increases. If not
properly maintained, for example through constant cleaning and refactoring, the system
becomes increasingly complex and disorganized... Fixing one bug introduces others, and
modifying one part of the software breaks several others - it's a bit like a domino effect. In the
end, the code base becomes unreliable. And what's worse, it's hard to bring it back to stability..

Testing can reverse this trend. They act as a safety net, a tool that provides insurance against the
vast majority of regressions. Testing ensures that existing functionality works, even after new
features have been introduced or code has been reworked to better meet new requirements
better adapt to new requirements

@regis_ate | www.regisatemengue.com 15
Unit Testing
Unit test objectives

Definition: Regression occurs when a feature stops working as expected after a certain event
(usually a code change).

The terms regression and software bug are synonymous and can be used interchangeably.

@regis_ate | www.regisatemengue.com 16
The Anatomy of Unit Test

@regis_ate | www.regisatemengue.com
17
The Anatomy of Unit Test
Using the AAA Pattern
The AAA pattern provides a simple, uniform structure for all the tests in the suite. This
uniformity is one of the biggest advantages of this model: once you get used to it, you can
easily read and understand any test. This reduces maintenance costs for the entire test suite.
The structure is as follows:

In the arrange section, you bring the system under test (SUT) and its dependencies into the
desired state.

In the act section, you call methods on the SUT, pass the prepared dependencies, and
capture the output value (if applicable).

In the assert section, you check the result. The result can be represented
by the return value, the final state of the SUT and its collaborators, or the methods the SUT has
called on these collaborators.

@regis_ate | www.regisatemengue.com 18
The Anatomy of Unit Test
Using the AAA Pattern

@regis_ate | www.regisatemengue.com 19
The Anatomy of Unit Test
Using the AAA Pattern
We transform our test case
into an automated unit test
using a test tool. In this
screenshot, we're using the
vitest framework.

@regis_ate | www.regisatemengue.com 20
Tests Double

@regis_ate | www.regisatemengue.com
21
Unit Testing:Tests Double

Tests must be isolated

@regis_ate | www.regisatemengue.com 22
Unit Testing:Tests Double
Why do need tests doubles ?
Some units are inaccessible and slow to run. (example database unit)

@regis_ate | www.regisatemengue.com 23
Unit Testing:Tests Double
Isolation
What does it mean to test a piece of code - a unit - in isolation? The London School describes
it as isolating the system under test from its collaborators. This
means that if a class depends on another class or on several classes, all these dependencies
must be replaced by test doubles.

A double test: an object that looks and behaves like its


release counterpart, but is in fact a simplified version that
reduces complexity and facilitates testing.

@regis_ate | www.regisatemengue.com 24
Demo: Unit Testing

@regis_ate | www.regisatemengue.com 25
Integration Testing

Big Picture

Test Pyramid

Demo

@regis_ate | www.regisatemengue.com
526
Integration Testing: Big Picture

@regis_ate | www.regisatemengue.com
27
Integration Testing
What’s a integration testing ?

@regis_ate | www.regisatemengue.com 28
Integration Testing
Other view of Integration Testing

@regis_ate | www.regisatemengue.com 29
Test Pyramid

@regis_ate | www.regisatemengue.com
30
Test Pyramid

@regis_ate | www.regisatemengue.com 31
Demo: Integration Testing

@regis_ate | www.regisatemengue.com
32
End-to-End Testing

Big Picture

As / When / Then Pattern

Demo : End-to-End Testing

@regis_ate | www.regisatemengue.com
533
End-to-End Testing
Big Picture

@regis_ate | www.regisatemengue.com 34
End-to-End Testing
What’s end-to-end Testing

@regis_ate | www.regisatemengue.com 35
End-to-End Testing
What’s end-to-end Testing
End-to-end tests are a subset of integration tests; they verify the system
from the end user’s point of view. End-to-end tests reach out directly to all or
almost all out-of-process dependencies your application works with.

What is the Practical Value of End-to-End Tests ?

Test the system exactly as the user would interact with it.

@regis_ate | www.regisatemengue.com 36
As / When / Then Pattern

@regis_ate | www.regisatemengue.com
37
End-to-End Testing: As When Then

Identifying the Most Critical Business Functions for Testing

AS / When / Then

Then
When
As The response status
A `POST` request is sent to should be 201, The response
A User `/api/signup` should contain valid JWT token
and The user should be saved in
the database

@regis_ate | www.regisatemengue.com 38
End-to-End Testing: As When Then

Identifying the Most Critical Business Functions for Testing

AS / When / Then

Then
When
As The response status
A `POST` request is sent to should be 201, The Product
A User `/api/product` should be linked to the good
category and the inventory
should be updated

@regis_ate | www.regisatemengue.com 39
End-to-End Testing: As When Then

Bad Example

As When
Then
an artist I create an eveny
a new event ID is returned

@regis_ate | www.regisatemengue.com 40
Demo: End-to-End Testing

@regis_ate | www.regisatemengue.com
41
TDD (Test Driven Development)

Big Picture

Green Red Refactor Cycle

Demo : TDD

@regis_ate | www.regisatemengue.com
542
Big Picture TDD

@regis_ate | www.regisatemengue.com
43
TDD (Test Driven Development)

CODE FIRST TEST FIRST

@regis_ate | www.regisatemengue.com 44
TDD (Test Driven Development)

Test-driven development uses unit tests to drive the design of your code.

Test First Approach

@regis_ate | www.regisatemengue.com 45
Red Green Refactor Cycle

@regis_ate | www.regisatemengue.com
46
TDD (Red Green Refactor)

Test-driven development uses unit tests to drive the design of your code.

@regis_ate | www.regisatemengue.com 47
Demo: TDD

@regis_ate | www.regisatemengue.com
48
Demo: TDD

@regis_ate | www.regisatemengue.com
549

You might also like