One of the best things you can do when you develop software applications is TEST! I know nobody likes it, but hey, you need to do it right? With the advocation of frameworks today, you get all these great tools to build your software applications, but how do you test your framework code. ColdBox has revolutionized testing HMVC and framework code, since you can unit test your event handlers, interceptors, model objects and even do integration testing and true BDD (Behavior Driven Development) and test your entire application with no browser at all.
ColdBox has already all the hooks in place to provide Behavior and Test Driven Development via TestBox and mocking/stubbing capabilities via MockBox.
TestBox already comes defined in the
box.json of all ColdBox application templates. However, if you have a custom ColdBox app or a custom template, then you can easily install it via CommandBox:
// stableinstall testbox --saveDev// bleeding edgeinstall testbox@be --saveDev
Please also note that CommandBox ships with tons of commands for interacting with TestBox and ColdBox testing classes. You can explore them by issuing the following commands or viewing the latest CommandBox API Docs (http://apidocs.ortussolutions.com/commandbox/current)
# testbox namespace helptestbox help# generationstestbox create help# run teststestbox run help# Watch your files and execute the tests if they changetestbox watch# coldbox creation helpcoldbox create help
It might be that testing is tedious and takes time to get into the flow of Behavior/Test Driven Development. However, there are incredible benefits to testing:
Can improve code quality
Quick error discovery
Code confidence via immediate verification
Can expose high coupling
Encourages refactoring to produce testable code
Testing is all about behavior and expectations
Our recommendation is to do BDD and integration testing first. Unit testing is important but it is more important to verify that your requirements are met.