Lately, my team has been looking for better ways to create and maintain mocks in our TypeScript project. In particular, we wanted an easy way to mock out modules that we built using Sinon.JS.
Recently, I was tasked with creating a new screen containing a table of data for a project using React and Apollo. In the past, we would typically start by defining the database table, other access layers in between that and a GraphQL query schema, and finally the query on the front end using Apollo. This […]
Lately, I’ve been using Sinon.JS for mocking in my unit tests. By using mocks for dependencies inside functions, I can write unit tests that are resilient to a changing codebase. Functions with mocks can also be developed without worrying about the chain of dependencies that could affect the logic inside the functions.
It’s easy to overlook the importance of unit testing. Writing tests can be tedious. They must be updated constantly as code is refactored, and when you have a large code base, you may have to write many tests to even come close to testing all cases. Despite this, unit testing is a necessary part of […]
UPDATE: Justin Searls, the author of testdouble.js sent me an email with some notes on this post. I’ve added some his comments below to provide some additional context. I’ve been working in JavaScript-land for the last little while, writing lots of Node.js code. Since I practice TDD, I’m always trying to keep my eye on […]
Test-driven development is an essential discipline for any software craftsman. Similar to how accountants use double-entry bookkeeping as a safety net, software developers can use TDD as their safety net. If you need a refresher on TDD — and what it is and isn’t — I’d suggest my post on why Simply Writing Tests Is […]
When working with the GoogleMock C++ mocking library, you can get pretty far using only default expectation return values or explicitly specifying expectation return values. There are some additional options that can save you a lot of effort in some circumstances though. Let’s take a look at a few of them. Standard Values Consider an […]
CMock is an extremely useful tool that can make testing C programs nearly painless. Employing CMock is usually straightforward, but here are a few common sticking points and ways to work around them: Calling Functions in the Same Module How do you test a function that calls another function in the same module? Since the […]
Higher-level languages are great, but every now and then I like some good old C++. So I was a bit excited when I got the chance to use C++ recently on a piece of demo software. After spending a lot of time in Ruby and Javascript (or more accurately, Coffeescript), it was both comforting and […]
We recently started writing a mobile website using JavaScript as our framework. To test the JavaScript framework we decided to try Sinon and Jasmine . With Sinon a mock is created from an instance of an object. Needing to create an instance of a class to make a mock becomes difficult for classes that have […]