Pesquisar

quinta-feira, 30 de agosto de 2018

Why? What? How? The Importance of Test - Part 2

This is a second article about the importance of testing. If you didn't see the first post, click here to understand the basic importance to create tests.





What is TDD?

TDD or Test Driven Development is a simple method to test-first on the development software. We can see the TDD flow is very comfortable with Figure 1:


  1. The first step, you create a test, and you run it off course that will fail it because you don’t have any code for this test. Red color represents this step.
  2. The second step, represented by green color is more simplistic that first, write code to the test pass and run. It will pass off course.
  3. Back to the code and refactor it.

It’s simple but not common to use, but an important technique that you can use in your agile process. Let's get the example:

I used an iOS project and XCTest framework by Apple to show the TDD process.


My test testLog_WithValidString_ReturnStringLog function tries to call the method to debug of Log class with the message in parameter, off course, that failed, because my class Log doesn’t have the debug function, see the class Log below:


Now, doing the second step of TDD, we create a method to will pass the test:


and run the test before:


Now that the test passed we need to back the source code and refactoring it:


When you finish the refactoring, you need to run the tests (better when the project has CI) to check it:



Continuous Integration

A tool that is used to agile process is Continuous Integration or CI for:
“… a fully automated and reproducible build, including testing, that runs
many times a day. This allows each developer to integrate daily, thus
reducing integration problems." (Martin Fowler and Matthew Foemmel) [1]
Grady Booch firstly used the word Continuous Integration in your book — Object-Oriented Analysis and Design with Applications (2nd edition). He defends that all devs need daily send the code to mainline, and this process was adapted to Extreme Programming, see Figure 6. But differently of Booch saw, the XP process defends that this process needs to do many times of the day.


CI is better when you used with a good repository flow, is common to use GIT as a repository. Many types of flow can do it, but most used to specific branches are master, develop, feature branches, hotfixes and release branches. This branches and flow were presented by Vincent Driessen with your excellent article with the title "A successful Git branching model" [2].


With this git-flow, you can use the CI a particular branch and your team works without problem.

So, tests were created and inserted in Agile flow for many reasons: quality, security, assurance, etc. We have a TDD that was created by Kent Beck to facilitate a developer create tests, and we have a Continuous Integration tool to integrate the code with git and assurance the quality of tests and code.

How can I create tests?

We have many tools, frameworks, and IDEs to create tests and many of these frameworks were written with native language for easy adoption, see Figure 8:


References

[1] http://www.martinfowler.com/articles/continuousIntegration.html?cm_mc_uid=71146886230214599723323&cm_mc_sid_50200000=1460918642
[2] http://nvie.com/posts/a-successful-git-branching-model/