Unit Testing using GIVEN-WHEN-THEN Template(Part 1: Introduction)

What is Unit Testing?

Unit Testing in the overall testing process

Why need to write Unit Testing?

  1. A safety-net
    Unit Testing is mandatory when coming with CI/CD. Without such a mechanism like automated testing as a safety-net, who can guarantee we not deploy a defective service.
  2. Documentation
    Unit Testing also can consider better internal documentation than comments. It provides sample input and output, prerequisite to called the function and dependency
  3. Efficiency
    Unit Testing can save a lot of time because the coder only needs to focus on a single unit without worrying it will break another part of the project (Well, at least we know if something broken). The coder can jump directly to test to a specific function/method rather than from program entry-point (the main() function)
  4. Code Quality
    Existence of Unit Testing is one sign of a good project. Unit Testing not only said that the function/method is really working but in the process of writing it, it will affect and drive the entire project to good design.

Test-driven Development

Make specification for a function

function A(){
B(); // call function B
// Do something else
}
function B(){
// Do something
}

Behaviour-driven Development

Given-When-Then

GIVEN a context
WHEN some condition
THEN expect some output

--

--

--

Technology to write, life to grateful. Overthinking is good, only if it has the output. Fundamental is the main concern.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

3 Ways to Create Automatic File Backup in Windows 10 Easily

Pattern matching for the Java programmer : part 1

Building Semantic Data Catalogs

Data-Driven Design Approach to Building Batteries

What I’ve Learned from Giving Coding Interviews

ZOO Token Rewards Launch

Build And Host Fast Data Science Applications Using FastAPI

Strafe is Hiring: Senior Android Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Iman Tung

Iman Tung

Technology to write, life to grateful. Overthinking is good, only if it has the output. Fundamental is the main concern.

More from Medium

It’s a design pattern called: The Singleton

What is Inversion of Control ( IoC ) and what are its advantages?

Polymorphism in C# with Method Overloading And Method Overriding

Summary of What I learned in Design Pattern: Singleton