Software Delivery Using Test DR - Abhinav Kaiser PDF
Software Delivery Using Test DR - Abhinav Kaiser PDF
Introduction
By writing the unit test case first, the developer is setting a target
that is in sight. The unit test cases are meant to cover a small portion
of the functionality. Once the "target" is set using the test cases, the
developer will be able to write just enough code to make the test
case pass and no more.
After the unit test passes, the developer can write the next unit test
case, create a new target, and implement a solution that that meets
the goal.
Thus, we can see that designing tests first helps make the entire
development process smoother and more efficient, by allowing the
coder to set sights early and code just enough to meet the necessary
requirements. In fact, the more iterations before deployment, the
stronger the benefits of TDD, as unit tests are applied over and over,
ensuring that new features do not corrupt old ones.
So, in this iterative process, the test cases guide the developer in
writing the code, giving this methodology its name: Test Driven
Development.
TDD's Origins
When did TDD become a thing? This is a difficult question to answer
because there is no definite answer.
Beck writes that the principle of TDD is quite old; it was employed
during the age of mainframes. The practice that was followed by
developers was to write down the expected output and then write
the programs on punch cards. This was effective because the time
they got to play with systems was limited, making this the best
possible way for efficient use of their time. The output achieved on
mainframes were compared to the documented output, and this
would tell developers of the time if their program worked or not.
As mentioned earlier in the post, the first activity that you do in TDD
is to write a unit test case. To reiterate, the unit test case must be as
small as possible, and still be able to be independently tested.
In step 1, I start with the unit test case for the logo that I am going to
place on the web page. Nothing more nothing less.
Now, I have a unit test case and absolutely no code. Yet, I am going
to execute the test case. Why? In TDD, you always write code for a
failing test, and this is the reason why we execute the test case
knowing full well that there is no code to support it.
Executing the test case without code also provides the insurance
that the developer does not get carried away by the need to have the
code in place before writing the test case. It is an additional layer of
control that ensures that TDD is followed true to the spirit of it.
After the test has failed, then you write just enough code to execute
the test case successfully. It is a common practice among developers
to write plenty of code, more like a novel rather than the bullet points
that we are looking for in TDD. You should not write more code than
needed.
Now that we have the code that is needed to successfully pass the
unit test case created in Step 1, we execute the test again. If the test
fails, it indicates that the code developed is not sufficient to run the
test case. Go back to Step 3 to rework on the code.
If the test passes, the code meets the unit test controls, and can now
proceed to Step 5 for refactoring.
The code that has passed the unit test in Step 4 is put through the
process of refactoring where the code is made efficient.
After refactoring, the developer picks up the next piece of unit test
case, possibly the username field in the login page they're
developing. They write the unit test case for the username field and
repeat Steps 1 through 5. The process iterates until the feature or
software is fully developed.
The weak link in the process lies in the developer understanding the
requirements. Suppose the business analyst explains that the
customer’s requirement is to develop an account management
system, the developer can misinterpret the requirements and
develop something totally different, such as a customer relationship
management system.
There are other alleged drawbacks, such as the process taking too
much effort and time from a single individual. However, in that
aspect, I believe that there is value in writing the test cases first and
achieving clean code and code coverage. Having accurate code and
focused development, in my mind, justifies the overhead effort and
time spent.
Additionally, some say that the unit tests look to concentrate on the
individual classes and functions rather than the overall user stories
and customer requirements on a whole. I agree that the unit test
cases work at a micro-level and may not assess requirements
holistically. This problem is solved by methodologies that I am going
to introduce in the next section.
Alternatives to TDD
The drawbacks I discussed in the previous section generally get
addressed by the upgraded version of TDD. The most prominent
upgrades to standard TDD are ATDD and BDD.
ATDD
However, even ATDD has some drawbacks. What if both the tester
and the coder understand the requirements incorrectly? We may
need another layer of control and validation. This layer is provided by
the Behavioral Driven Development (BDD) methodology.
BDD
The next major difference when considering BDD is that BDD test
cases are not written in the usual scripting language. Rather, forms
of natural languages such as Gherkin is employed. Using a natural to
write acceptance test cases will equip the business analyst, product
owners, and customers to validate against the requirements. This
helps void any discrepancies between the code and its output but
adds a layer of complexity to the development process as code
needs to now meet Gherkin requirements.
Although BDD stands on its own today, it has taken its roots from
the TDD methodology. The principles of TDD invented decades years
ago continue to drive the industry through the development
methodology's variants.
LEARN MORE
×
STAY HOME. SKILL UP. SIG N UP NOW
Guides
Copyright © 2004 - 2020 Pluralsight LLC. All rights reserved Terms of Use Privacy Policy
We use cookies to make interactions with our websites and services easy and meaningful. For more information
about the cookies we use or to find out how you can disable cookies, click here. Disable cookies
ACCEPT COOKIES AND CLOSE THIS MESSAGE