TFP
Developers should always begin Development with an
“Abstraction of Intent”
as a
“Repeatable Validation of Functionality”
inside a Testing Framework
TFP Abstract:
Defining the intent of small behavior Methods as structured Unit and Integration Tests before the actual code is developed will lower the Total Cost of Ownership (TCO) of the code.
This will reduce the maintenance costs by creating a development environment that allows for a quicker understanding of the intent of the code for future maintenance efforts.
Description:
Software development is inherently complex.
Enterprise development can be magnitudes more complex than a simple Company Web application.
This complexity is extremely costly to the Client not only in initial development but in the maintenance of the developed solution over the Software Development Life Cycle (SDLC).
Serious consideration must be taken to manage
this complexity in all design stages, development
and in maintenance activities
Get a Clear Understanding of the “What”
… Of your Development Requirements
…… Before You Try to Develop the “How”
This understanding will help you have a clearer idea
of where you are going in your development efforts
Test Driven Development (TDD)
TDD allows you to define the “Abstraction of Intent”, what the success criteria is for a given code behavior before you actually create the code for the intended behavior.
This development requires a “Paradigm Shift” in your thought process.
The normal behavior of creating the code and then seeing if it works in the application must be altered 180 degrees.
The TDD Process:
-
Create the Abstraction of Intent as a Failing RED Test
-
Create the Code for the Test to Pass in the current Testing Code page as a GREEN Test
-
Refactor the Initial Passing Code into a Better Design complying with the Design Principles and Code Standards. This is the YELLOW Test
-
Use Move Refactoring to move the Concrete code to the correct Namespace in the Assembly Under Test
You must create a Test Method that defines “What” the code “Will Do” before the code is developed.
This is the Abstraction of Intent.
This Test Method is created as a Failing Test, Assert to: true equals false.
This indicates that the code is yet to be created but an understanding of what the code method is to accomplish is clearly understood.
This is called a RED Test.
The key to Test First Development is to create the initial functional code within the test environment, on the same code page as your Abstraction of Intent.
This puts all the software components, for the validation of the intent of your code, in front of you at all times while you are creating the concrete code.
Your task is to just get the test to pass with working code. Be a “Subtractive Developer”.
Don’t worry about total compliance with the Design Principles and all Code Standards at this time.
Create the code in a Professional manner but the Refactor stage will fix any “Code Smells” created.
Just get the test to comply with the acceptance criteria defined in the test abstraction. This is the GREEN Test.
The next step in the TDD Process is to refactor your initial code to a better design.
Your code must comply with the Design Principles and Code Standards for the Modern Developer.
This refactoring effort will improve performance, readability and a better understanding of the underlying intent of your code for future developers to maintain.
The initial success criteria were to get the code to work.
You may have violated the Single Responsibility and Open / Close Principles.
Temporary variables and redundant Type declaration creating code noise may have been implemented for better initial understanding and debugging.
Your naming convention may have been for expediency of testing.
This was fine in the GREEN Test stage but will be corrected in this stage.
This is the YELLOW Test.
Here is a List of Common Refactorings:
+10 Safe Refactorings
Here are Ten Code Clean ups that have minimum risk to the legacy environment:
- Remove Unused “using’ Statements
- Convert Private Data Members into Auto-Properties
- Initialize Class Level Private Properties in a Default Constructor
- Rename Bad Property Names into the Correct Class Naming Convention
- Create a Region at the bottom of the page for all Private Methods as a Helper Section
- Identify the Methods in the Class that are ONLY used in that Class and move to Helper Region
- Replace Explicit Type Names with ‘var’ to reduce the “Code Noise” in the Type
- Identify and Move the Value of ‘temp’ variables: Variables that are created and only used ONE Time. Move the variable statement to the One and Only One usage to improve performance.
- Extract Helper Methods from Large Methods and place in the Helper Region if only usable in the current Type. Extract and Move to a Common Utilities Helper Type for Code reuse by the team. Always document Common Helper Methods in a centrally located and published Knowledge Repository.
- Extract complicated algorithms and lengthily code from Conditionals such as ‘try/catch’, nested ‘ifs’ and ‘switch’ statements. Place in the Helper Region. This will improve performance at Run-time
Moving the Refactored Code into the Assembly Under Test:
The final step in Test Driven Development as a Test First methodology is the move the code to the proper namespace in the Assembly Under Test.
This is easily accomplished with a refactoring tool such as ReSharper from Jet Brains.
This is the number one tool that all Modern Developers need to have in their Science Toolbox.
ReSharper will move the code to the folder structure
you create in your project assemblies
and set all required references and namespace
All you have to do after selecting the code and having ReSharper do the Move Refactoring is run the test to validate the functionality within the Assembly under Test.
Wisdom Pearl #103: Managing Technology Results
If You Can’t Measure It
… You Can’t Manage It
The Test First Principle, using TDD,
will allow you to manage your code
by creating repeatable, measurable criteria
that will run Today, Tomorrow,
Next Week, Next Month and Next Year
The following two tabs change content below.
I am a Principal Architect at Liquid Hub in the Philadelphia area specializing in Agile Practices as a Certified Scrum Master (CSM). I use Test Driven Development (TDD) and Acceptance Test Driven Development (ATDD) with Behavior Driven Development (BDD) as my bridge to Agile User Stories Acceptance Criteria in a Domain Driven Design (DDD) implementing true RESTful services
Latest posts by Brad Huett (see all)
- DevOps: A Bridge to Your DevOps Culture - March 25, 2016
- Embracing Test Driven Development (TDD) - March 25, 2016
- DevOps: Delivering Agile Projects - March 25, 2016