Tag Archives: Unit

Automated Tests Purposes

Automated tests: Why? How they help? Who needs them?

There are many types of automated tests out there. Let’s see the most used types of tests and understand how each one is useful.

Types of tests covered are:

  1. Unit Tests are isolated, focused on methods and classes. White box tests.
  2. Integration Tests are for checking how two different modules integrate. Black box tests.
  3. Integrated Tests are big, large tests showing how many modules integrate, with a business purpose. Black box tests.
  4. Acceptance Tests are showing that a features works well. Black box tests.
  5. Contract Tests are a special type of tests, that verify polymorphism integration of multiple components or classes.

Let’s take them one by one in detail.

Automated Tests System Under Test

Read More →

Legacy Coderetreat: Episode 13 – Document Possible Bugs with Tests – Codecast

Document Possible Bugs with Tests – Codecast

Blog post series

This blog post is part of a series about legacy coderetreat and legacy code techniques you can apply during your work. Please click to see more sessions about legacy code.

Code Cast

This is a codecast in Java.

In the previous episodes we reach the moment when we extracted one simple class. We used the The Rule of Three and pure functions. This newly extracted class is covered with characterization tests. Then we wrote some unit tests in the following episode. But some of the behavious seemed strange, and we thought they might be bugs.

Because we are never sure when working on existing code if some behavior is a bug or a feature, we want to document all the suspicious cases. In order to do that, I am presenting three methods: use an annotation, prefix the test, use a different class.

Bug or feature? Check out the codecast to see all of them in action.

Read here more about this concept in my blog post.

When we document defects with tests it is a good idea to group all the tests documenting possible bugs one after the other. The discussions with the business persons are easier and you do not need to search the next test again and again.

Always discuss with business persons before changing the code. Often one might think they understand what the code does, but the situation if often very different in practice. Think to verify every detail with business analysts before changing the existing code.

Legacy Coderetreat: Episode 12 – Unit Testing on Legacy Code – Codecast

Unit Testing on Legacy Code – Codecast

Blog post series

This blog post is part of a series about legacy coderetreat and legacy code techniques you can apply during your work. Please click to see more sessions about legacy code.

Codecast

This is a codecast in Java.

In the previous episodes we reach the moment when we extracted one simple class. We used the The Rule of Three and pure functions. This newly extracted class is covered with characterization tests. But that is not enough, we want to continue adding other types of tests to understand the system better.

This is why during this episode you will see how to add unit tests to code extracted from a legacy code class. These tests have a small granularity level than the characterization tests we already have. This is the moment to dive more into details.

See this video to understand how you can document the current state of the system, by unit testing on legacy code.

Read here more about this concept in my blog post.

We started with a class having non-public methods. The purpose of this session was to start covering the class with tests. In this moment we have short and clear unit tests, written in isolation of any slow dependencies. These tests are fast and we need to run then any time we will change the production code, to make sure we do not introduce defects.

In the same way as shown in the last blog posts, we can extract pure functions, extract classes and then cover these classes with unit tests.

Software Lost Video: James Shore – Rigorous, Professional Javascript

James Shore is one of the promoters of TDD in Javascript. He is presenting codecasts on his website Let’s Code Javascript about how to work effectively in Javascript.

As James says:

“JavaScript Needs Test-Driven Development

If you’ve programmed in JavaScript, you know that it’s an… interesting… language. Don’t get me wrong: I love JavaScript. I love its first-class functions, the intensive VM competition among browser makers, and how it makes the web come alive. It definitely has its good parts.

It also has some not-so-good parts. Whether it’s browser DOMs, automatic semicolon insertion, or an object model with a split personality, everyone’s had some part of JavaScript bite them in the butt at some point. That’s why using test-driven development is so important.”

Rigorous, Professional Javascript

Read More →

Legacy Coderetreat: Part 8 – Extract and Override

Extract and Override

Blog post series

This blog post is part of a series about legacy coderetreat and legacy code techniques you can apply during your work. Please click to see more sessions about legacy code.

Purpose

Almost always when needing to test existing code we bump against dependencies that make the system untestable. This technique is useful to extract the static dependencies. After that we can use dependency inversion in order to be able to really test the systems.

With this technique we can transform untestable systems into testable systems, step by step. The steps are small because we want to enable safety while changing the code.

Extract and Override

Extract and Override

Read More →