Software Testing & TDD
by Ronni Kahalani, Copenhagen School of Design & Technology.
With inspiration from the book Software Engineering - A Practitioner's Approach.
Includes Test Driven Development (TDD) Tutorial
Building a simple calculator the TDD way.
Tutorial link: TDD Demo Slide 58: TDD Demo.
Who am I?
Thank you for stopping by.
I’m Ronni. I hope you’re well and wish you a safe and worthy journey.
This presentation is part of the Software Engineering Series, from my lectures at Copenhagen School of Design & Technology.
You can view the Introducing Myself, if you want to know a little more about who I am.
All my presentations and materials are free and available at my blog post: Software Engineering.
Don’t let me uphold you,
continue your journey, go to next slide.
2
Agenda
Testing approach
According to IEEE Std 829-1998,
Software testing is defined as
“the process of analyzing a software item, to detect the differences between existing and required conditions (defects) and evaluating the features of the software items.”
Test Pyramid
User Interface Tests
Fulfilment of business requirements, in a real customer- /user environment. End-to-end test via desktop- or browser platforms.
Acceptance Tests
Fulfilment of business requirements, by actual users.
Unit Tests (Level 0)
Validating an isolated single unit for its correct behavior to complex and important decision making.
Integration Tests
Fulfilment of components or units interact with each other, in the form of commands, data exchange or database calls…
Types of testing
Software Testing
“You test quality, if it isn’t there before you start testing,
it won't be there when you’re done testing.”
Testing is not a fix for quality, at the end of the process.
Given-When-Then Acceptance Criteria
Defines an acceptance criteria, which can be automatically interpreted and tested.
Example: Product Page
From book
The conflict between the proud developer(s) and tester that want to break it down and tear it apart to find the errors.
Criteria of Done = Acceptance criteria (Given-When-Then)
When are we done testing?
Best Testing Strategy
What is a best testing strategy?
Best Test Strategy
The best test strategy Is when the software testers,
Best Test Strategy
In agile
Test recordkeeping
Test cases can be recorded in a simple format, in Google Sheets, and linked to in a relating story in Jira or another agile project tool.
Containing
Generic Test Characteristics
Effective testing needs technical reviews, to find errors before the test phase commences.
Testing begins, at the component level and works “outward” towards the integration of the entire system.
Different testing techniques are appropriate for different engineering approaches and at different points in time.
Testing is done by the developer of the system and in large projects, independent test-teams can be assigned.
Verification and Validation (V&V)
Verification refers to a set of tasks that ensure that software correctly implements a specific function.
Are we building the product right?
Validation refers to a different set of tasks that ensure that the software that has been built is traceable customer requirements.
Are we building the right product?
Verification- and Validation activities
White Box Testing (inside the system)
Sequence
If
While
Until
Switch/Case
The Basis Path
path 1: 1-11�path 2: 1-2-3-4-5-10-1-11�path 3: 1-2-3-6-8-9-10-1-11�path 4: 1-2-3-6-7-9-10-1-11
Cyclomatic Complexity
A quantitative measure of the logical complexity of a program.
Cyclomatic Complexity
Cyclomatic complexity
Computed in 3 ways:
#1
The number of regions.��#2
V(G) = E - N + 2
where E is the number edges, N is the number of nodes.�
#3�V(G) = P + 1
where P is the number of predicate nodes.
Cyclomatic complexity
The flow graph has four regions.
V(G) = 11 edges - 9 nodes + 2 = 4.
V(G) = 3 predicate nodes + 1 = 4.
Control Structure Testing
Black Box Testing (requirements)
Object-Oriented Testing
Functional Tests
Verifies that the software performs specific functions as expected based on requirements.
Functional Tests
The V Model
Unit Tests
The most basic unit (class) or component of an application is tested.
Usually done by a developer to ensure the smallest testable code is working fine.
It is a White Box testing technique.
Location in the V-Model
Integration Tests
Interface Tests
System Tests
Regression Tests
Smoke Tests
Sanity Tests
Browser Tests
End-to-end Tests
User Acceptance Tests
Non-functional Tests
Validates the quality attributes (performance, usability, reliability, etc.) of the software.
Non-functional Tests
Performance Tests
The performance of the application is measured while subjecting the application to real-world conditions.
WebLOAD, LoadView, NeoLoad, LoadNinja, Appvance, LoadRunner, Apache JMeter, Loadster, LoadImpact, Testing Anywhere, SmartMeter.io, Tricentis Flood, Rational Performance Tester, LoadComplete, etc.
Stress Tests
Application is subjected to anomalous conditions, which will not happen under normal circumstances.
Volume Tests
How well the system behaves when a large volume of data and operations are handled by the database.
Load Tests
The performance of the application under expected load as in the real world is measured.
Security Tests
Security of the application from the point of view of the network, data, system and the application is tested.
Scalability Tests
In case the application needs to be scalable in future, will the architecture and design allow?�
Ex., if we add more servers, have more database transactions, increase the user load in the future, will our application allow that?
Usability Tests
Deals with the usability of the system from a user’s perspective.
Maintainability Tests
Maintaining the application for future expansion and requirements is important.
�How well does the application accommodate changes and updates?
Compatibility Tests
The compatibility of the application is tested with regard to different
The application should be able to perform well on the prioritized environments by the customer.
Recovery Tests
Checking whether the app can recover from crashes and how well it recovers.
Test Driven Development (TDD)
Test first, fail fast and building quality testable code.
Test-Driven-Development (TDD)
Maven Projects (POMs)
<project>
<modelVersion>1.0.0</modelVersion>�� <groupId>org.example</groupId>� <artifactId>TestDemo</artifactId>� <version>1.0-SNAPSHOT</version>�� <properties>� <maven.compiler.source>17</maven.compiler.source>� <maven.compiler.target>17</maven.compiler.target>� </properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
…
</dependencies>
</project>
Example Maven pom.xml file
Maven Scopes
compile (default scope)
provided
runtime
test
system
import
Dependencies with scopes provided and test will never be included in the main project.
Maven Build Lifecycles
The default lifecycle comprises of the following phases:
Maven Build Window
Maven Dependencies
JUnit Engine
JUnit Platform
Mockito (for mocking)
Maven Dependencies
JUnit Engine
JUnit Platform
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Mockito (for mocking)
JUnit Annotation Lifecycle
TDD Demo
In Java Maven Projects.
Test Case
JUnit & Mockito Links
Questions?
Anything? What’s on your mind? Come on ask me anything…
Feedback?
Thank you for your precious time.
I hope it was worth it and would love to get your feedback.
Testing types, techniques and tactics
Testing Patterns