Skip to main content

Mocking Unlocked??

I'm a huge fan of both CommandBox and TestBox from OrtusSolutions and have become a believer in  the usefulness of testing. That in and of itself has had it's benefits in making me a more analytical programmer, understanding flow better, forcing me to write shorter methods, etc.

However, for the life of me, I couldn't get to first base on mocking. Conceptually, I knew it was when something was pretending to be something else but I didn't even know enough to understand the documentation (which is more of statement about me than the docs). As a result, I've been using Testbox in a valuable but limited way by using it to run a function without having to go through an interface which may or may not exist yet. The problem is that I wasn't separating it from any other function, table, web call or process with which it interacts. This in an of itself is a valuable process but it's not really unit testing and with that statement comes the following dialogue which I've published somewhere else.

Glossing over the argument about unit testing, we're launching a new automatic build system at work so testing, and more importantly, testing that ran quickly, covered multiple scenarios and was not attached to a database or actually called web services was needed. This precipitated me  actually putting keystrokes to concepts and figuring out how this mocking thing works.

It turns out to be much easier than I thought.

To figure out how this worked I wanted to set up a simple function but one with ever increasing complexity of architecture. By that I mean that ultimately all my function did was to accept two numbers and then return an answer but did so in different ways. The rules were that I had to submit the same two numbers and get an answer. I was using TestBox and it's built in partner, Mockbox. The test could only run the function being tested and all information needed to run that function had to originate with the test, no outside dependencies.

The scenarios that I put together were these:

1. A public function which accepted two numbers, multiplied them together and returned the answer
2. A private function which accepted two numbers, multiplied them together and returned the answer
3.  A public function which which accepted two numbers, queried a database for the answer and returned it.
4. A public function which accepted two numbers, obtained a query from another function in the component and then returned the answer. This actually used MockBox for the first time..

These went surprisingly well and I'll be outlining other techniques as I explore this more thoroughly.



Comments

Popular posts from this blog

Creating Stories and Tasks in Jira: Personas and our Software Development Team

Part of the CI/CD Development Series The next step is developing who is on our hypothetical development team. Given that it has a React front end and ColdFusion as the Server Side language, I came up with the following personas, all of which have their own needs and considerations for our development environment. I've listed all the jobs that need doing, not the people involved since, even on a small team or a team of one, these "hats" are all worn by someone, even if it's the same person. Personas for our Project Dev Ops Coordinator - The person responsible for smooth and accurate deployments CF Developer - The person responsible for the API and fulfillment code development and maintenance. React Developer - The person responsible for the front end development Database Coordinator - The person responsible for the schema, data, up time and, presumably the testing databases used by the developers. Lead Developer - The person responsible for coordinat...

As the Dev Ops Manager, I need to start planning our CI/CD release process

Part of the CI/CD Development Series Once we have our Deployment Diagram designed, we need to figure out out to get from here to there. If the end point is the appropriate server environment, the starting point is the developer with his/her hand on the keyboard. These steps take place on a variety of machines, within various process and can changes based on what files are checked in or not. At the moment, we've only created the early basics as seen below. The Beginning of our Deployment Activity Chart Even though there is quite a long way to go there are some elements which we have already been determined. For example We have determined the broad strokes of our technology stack. This is going to be React on the front end and ColdFusion on the server side. We have determined that we are going to be using linting on both the CF and React paths. CFLint for the CF and ESLint for the Javascript We have determined that we are going to be formatters - CFFormat for CF and...

As the Dev Ops Coordinator, I need to set up our git repo into several branches with the appropriate permissions for each one

Part of the CI/CD Development Series The core of every CI/CD process is the code repository whether it be Git, Mercurial, SVN or whatever. The general idea is that it allows multiple developers (or whomever) to access your code in the appropriate way in the appropriate level. This can either be the ability for anyone to pull an open source project but not write to the repo directly or full access to a developer on your team to create branches, push to master or anything that needs doing. For our project, we're using git although the hosting provider was up for discussion between Github, Bitbucket by Atlassian or CodeCommit on AWS. We decided to go with AWS for two reasons. 1. We are going use other tools in AWS as part of the build so we decided to keep it all together. 2. We needed to solidify the ins and outs of using IAM for the process. Basic Steps Create the Repo Create the branches we need Use IAM to apply the appropriate permissions to each branch and to set up ...