Ed Bartram talks about “Assert Control Over Your Legacy Applications (TestBox Quick Start)” in this episode of ColdFusion Alive podcast with host Michaela Light.
"Unit tests are typically testing the logic within a particular method or group of methods and not anything else that those methods are and that includes external dependencies such as a database. So what we do is we write integration tests which are structured much like unit test to test those external dependencies to make sure that the code that you have that's making those calls out actually work correctly without error and then you can even in the case of database calls insert records into it in order to do your unit tests against let's say, read function to make sure that it's coming back correctly so it's doing what you intended it to do." - Ed Bartam
Show notes
Why unit test?
A unit is a method, function or small group of same
Why do it?
Refactoring is safer
improving quality and reliability of their application
Faster finding bugs when you change code
Better deployment during your build process
What is integration testing
Testing logic vs testing external dependencies
Functional tests with Selenium
What TestBox?
A test creation framework and scripting language
Set up - before test suite is run
Tear down - after test suite is run
Before unit test is run
After unit test is run
Automated vs manual testing
Good automated testing characteristics
Repeatable
Can be run at push of a button
One test
A suite of tests
All unit tests
Works with CI (eg Jenkins or Ant) so tests are run during your build process automatically
Consistent test results independent of the environment (eg database)
Full coverage of all code in the unit
Independent of other tests - can be run in random order - no dependencies between tests
Easy to detect if an error occurs and report on it so you can
Test setup and tear down of dependencies
TestBox does all the above
Need to move code to methods or functions
TestBox tips and best practices
What tests to write
How to name them
Test_[method name]_[When to test]_[Expected enresult]
How to write them
When to write them
TestBox color coding
Tests that pass - Green
Test that fail - Yellow
Test that errors out - Red
Result actions
CI backout the deployment
Slack
Email
Ring a bell via a Raspberry Pi
Who broke the build gets to wear a special hat for rest the day
Free open source
Doesn’t require ColdBox
Paid support is available
CFML slack testing channel
Replaces mxUnit
Mocking and MockBox
Spies and Stubs too
Blackbox unwritten code
Design patterns
What is a legacy application?
Michael Feather book working effectively with legacy code
Test Driven Development (TDD)
Write a little bit of your test before your code
Then write a little bit of code to pass the test
Repeat
Know as “Red-Green testing”
How to install TestBox quickly in your existing environment
CommandBox one line install of TestBox
Or download and manually install
How do we improve our code coverage then?
which prescribes writing tests and then writing code to make those tests pass.
Start with current bugs you are working on fixing
First pull out the queries into methods and writer tests for them
Second pull out logic into methods and write logic
Could move to MVC - but not required
CFMs = views and controller
CFCs = model
Why CFers resist writing tests
Takes too long to writer
Too hard to write tests
Too late to write tests for existing code
Why are you proud to use CF?
WWIT to make CF more alive this year?
What are you looking forward to at Into the Box?
Mentioned in this episode