0% found this document useful (0 votes)
12 views12 pages

SWEN3165 Lecture 2

The document discusses Test-Driven Development (TDD) and Behavior-Driven Development (BDD), highlighting their advantages and disadvantages. TDD involves a red-green-refactor cycle but can be time-consuming, while BDD focuses on user behavior and is suited for custom web projects. It also outlines different types of tests, emphasizing the importance and benefits of Unit Testing in validating code functionality and providing quick feedback to developers.

Uploaded by

kid unique
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)
12 views12 pages

SWEN3165 Lecture 2

The document discusses Test-Driven Development (TDD) and Behavior-Driven Development (BDD), highlighting their advantages and disadvantages. TDD involves a red-green-refactor cycle but can be time-consuming, while BDD focuses on user behavior and is suited for custom web projects. It also outlines different types of tests, emphasizing the importance and benefits of Unit Testing in validating code functionality and providing quick feedback to developers.

Uploaded by

kid unique
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/ 12

SWEN3165

Unit Testing

Mr. Matthew Ormsby

University of the West Indies


Mona, Kingston, Jamaica
What is TDD?

This practice of writing failing tests, known as the red-green-refactor cycle.


TDD - Disadvantages

Despite its efficient results, the approach is encumbered with certain difficulties:

Time consuming process. The whole ‘Red-Green-Refactor’ cycle of the TDD work
requires investment of time into each part. This adds major time to the first iteration
of the project and influences the costs of the project. It pays off in the long run saving
time spent on QA testing and debugging, but equally it can turn out to be unnecessary.
Plus, for the same reason, TDD is hard to implement for rapid development.
Need for updating tests. With TDD, if you update the function, even without changing
the inputs and outputs, you may also need to update the test.
What is BDD?

Behavior-driven Development testing appeared as an alternative to the TDD method in


the early 2000s. Its approach, though also test-first, is focused on the end user’s needs
and his or her behavior to satisfy them by using the so-called Executable Scenarios.

This results in distinctive peculiarities of the approach:


• Fixing the desired outcome in a ubiquitous language.
• Removing the focus from the technical side to the aim of the software.
TDD vs BDD

BDD is not going to replace TDD in the development cycle for all projects.

There is a general distinction between them: TDD is better used for systems that have
3rd party API calls, cron jobs, data exports/imports and other side implementations,
whereas BDD works as a better solution for ecommerce websites or HR systems, i.e.
for custom web development projects driven by actions of the end user.

In most cases both solutions can be applied together, thus each solving its particular
tasks: BDD describes a system’s behavior, while TDD explains how this behavior should
be implemented.
Different Types of Test

• Unit Test – test of small code unit: file, class,


individual method or subroutine

• Integration Test – test of several units combined to


form a (sub) system,

• System Test – test of a system release by


”independent” system testers

• Acceptance Test – test of a release by end-users or


their representatives
What is Unit Testing?

Unit Testing is a method in which a developer tests if individual units of source code
are fit for use.

• Can be used to validate that the code functionality still works after code changes.

• It is a form of documentation.

• You do not have to define unit tests for every single method you have. A careful
developer will know that their unit tests must cover the cluster of objects that form
their application.
Unit Testing – Example
Unit Testing – Example
Unit Testing – Example
Karma Unit Testing
Tutorial: http://www.bradoncode.com/blog/2015/02/27/karma-tutorial/
Benefits of Unit Testing

Tests create a feedback loop that informs the developer whether the product is
working or not.

• Unit tests are fast


• Unit tests are reliable
• Unit tests isolate failures

You might also like