Posts tagged with unit tests

  • Testing null, empty, blank

    Sep 14, 2019

    In many cases, when you have a method that accepts a mandatory string parameter, you want to verify that the parameter contains a value that isn’t null, nor empty, not blank (i.e. consisting solely of whitespace characters). While writing the check is easy, testing it can be a bit annoying.

  • Code coverage on integration tests?

    Aug 11, 2018

    Should you collect and measure code coverage on integration tests or only unit tests? In this post I’ll share some thoughts on this topic.

  • AssertJ cheatsheet

    Apr 22, 2018

    AssertJ is a an assertions library for unit tests in Java that is well worth considering. Here are some examples.

  • Using sinon mocks

    Jun 4, 2016

    In the previous posts we had a look at sinon spies and stubs. There is one more technique we can use in order to orchestrate our test dependencies: mocks.

  • Using sinon stubs

    May 28, 2016

    In the previous post we had a look at sinon spies. With spies, we are able to determine if a specific function was called or not. Usually the dependencies between units are more interesting, they involve units co-operating, exchanging data and so on. Spies do not suffice. Let’s have a look at another technique, using stubs.

  • Using sinon spies

    May 21, 2016

    In the previous post, we implemented a new feature for our calculator: it makes a bell sound when you divide by zero. The bell is a simple function that the calculator calls and it is provided as a constructor dependency. We wrote a unit test for this as well, but the code for that is a bit verbose. Let’s see how we can use a mocking library like sinon to reduce and standardize the testing code.

  • The division by zero bell - Dependencies in unit tests

    May 14, 2016

    We left our calculator in the previous post in a decent state, being able to do the four basic mathematical operations. In the special case of division by zero, we want the calculator to make a noise like a bell. Let’s see what we can do about this.

  • What is code coverage?

    May 7, 2016

    Last time we had a look at test driven development and our calculator learned how to do multiplication. In this post, we’ll add division and talk a bit about code coverage and unit test quality.

  • What is Test Driven Development?

    Apr 30, 2016

    Let’s continue building up our calculator with more mathematic operations. So far we have addition and subtraction, so multiplication comes up next.  In this post, we’ll have a look at test driven development. Even though the examples are a bit trivial, I hope they’ll outline the important points.

  • A closer look to a basic unit test

    Apr 23, 2016

    In the previous post we started writing a basic Calculator class and added the first unit test. Let’s have a closer look at that unit test and extend our calculator with more features.

  • What is a unit test and why should I care?

    Apr 16, 2016

    So, let’s start with some basics. What is a unit test? A unit test is a piece of code that validates the expected behavior of a unit in isolation. I guess the next question is, what is a unit? A unit is the smallest piece of code in a given programming language. Typically that is a function or a class method. Let’s see it with an example.

  • When developers cannot unit test

    Apr 9, 2016

    Unit tests is an essential method of ensuring quality and predictability of software. In my current work, we have been going through a hard learning curve involving many factors:

    • developers not familiar with unit tests.
    • a proprietary technology ecosystem where the community is typically not practicing unit tests at all.
    • a legacy code base not written with unit tests in mind
This site uses third party cookies from Google Analytics and Google AdSense Accept and close popup