SWEN3165 Lecture 2
SWEN3165 Lecture 2
Unit Testing
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?
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 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.