Paytonrules Ramblings
  • Posts

Posts

October 2, 2015

Testing Private Methods - In Any Language

“How do I Unit Test Private methods in [language]?” is a question that comes up a lot. As in “Unit testing private methods” has 3,820,000 results on google1. It’s clearly an issue for numerous developers, despite the fact the answer is easy. Don’t Well that’s the end of that blog… What? I should test everything! Of course you should, but if you’re worried about unit testing a private method then you’re not letting the design emerge as you write tests.
August 24, 2015

Help I Can't Test This!

In real world TDD you almost never get to write tests that look like this: describe("Stack", function() { it("should begin empty", function() { let stack = Stack.create(); expect(stack.size()).toEqual(0); )); }); The above is the typical first test in the Stack Kata - written in JavaScript. It seems nice because it’s straightforward and easy to teach, but it ends up being a problematic example because nobody ever writes this kind of code unless they are doing a Kata.
July 13, 2015

Should You Really Ignore Your Database?

Recently I wrote about getting your unit tests off your database for the sake of your build. In particular I wanted to address two problems that happen on build machines: Builds fail because of “stray” data in the database. Builds fail because of parallel data in the database. The problem presents itself when hundreds or even thousands of tests directly depend on the database. A huge part of fixing this problem is getting off the database any place it isn’t absolutely necessary, and it’s probably not as necessary as you think.
May 31, 2015

Simple Mock Objects in Go

And almost any other language… I Don’t Have a Mocking Framework! Let me paraphrase what I read on a golang-nuts thread: Go doesn’t have a built in mocking framework, and gomock is not mature enough for production! When will we be able to do TDD in Go? C’mon man. Of COURSE you can do TDD without a mocking framework. People do that every day, sometimes by choice. You can do TDD in Go right now, and you can do it without using gomock at all if you don’t like it.
May 15, 2015

Build Broken? Stop Using Your Database!

Your build machine. It’s a damn mess. It’s broken all the time. It’s flaky. It makes developer’s sit and wait for hours just to make sure that their code passes, only to find out the build failed because somebody else’s code broke it. If you followed the rule of “we don’t ship broken builds” you’d never ever ship. So you ship and the customer(s) finds bugs. Sound familiar? You aren’t alone.
May 1, 2015

How To Test A Callback

Function Callbacks, or lambdas, or blocks, can frequently be nasty to test. Or at least they feel nasty to test. Let’s take a simple JavaScript example: $("button").click(function() { $("p").html("Warning! A button has been clicked!"); }); This can seem impossible to test, or nearly impossible. In fact callbacks can be really difficult for even experienced TDD practitioners to test. Fortunately it’s really not that hard. Option 1 - Invoke the Callback JQuery actually makes this pretty easy with clicks.
April 22, 2015

I'm Afraid to Change This Code!

We’ve all been there before. You’re working in your spectacularly complex codebase1 and you discover code that looks something like this: public void OnOk() { DatabaseDriver db = new ForeignDB(); Webservice ws = new Webservice(); // DON'T DELETE THIS! for (int i=0; i < 1000; i++) { sleep(1); } db.open(); db.sendRawSQL("Update id in TABLE where INNER_JOIN %1", this.CompletedQuery); db.
April 1, 2015

My Boss Won't Let Me Clean Code, Now What?

I hear it all the time. The lament goes something like this: I don’t have time for clean code because my deadlines are insane! My boss thinks I’m wasting time with all this testing and my coworkers think I’m a perfectionist. Clean code can’t happen in my company because everybody is stupid! What do I do now? If you’re test infected the reaction tends to be to evangelize. You start telling everybody that they should or must write tests, because if they don’t they are lazy.
March 14, 2015

Where are Good Examples of TDD?

Learning has TDD at a great feedback loop when you’re a beginner. You write a simple test, you make it pass, you write the next one. Your first test will probably take hours. Your second one takes an hour. Your third takes minutes and you have your aha! moment. This is why I recommend katas as an early step to get started. If you do the prime factors kata you’ll see value really quickly.
March 6, 2015

The Evidence For TDD

This blog was going to be something completely different. Every week I do some trawling around the internet, looking for problems people are having that I can fix. This week I found a lot of comments like this: Once a programming team has adopted a methodology it’s almost inevitable that a few members of the team, or maybe just one bully, will demand strict adherence and turn it into a religion.
February 13, 2015

Write Tests Now

Many of you have been generous enough to answer a few questions from me when you sign up for my newsletter, the responses tend to look a lot like this: I’m a software developer and I think TDD is great, but I have tons and tons of legacy code and I don’t know how to get started. The organization wants to be Agile but they won’t test the millions of lines of software already written.
January 30, 2015

A New Cycle For TDD

Earlier this week I stumbled across an entertaining list of TDD Anti-Patterns, and had some fun reading through them. One I liked in particular was this: Second Class Citizens - test code isn’t as well refactored as production code, containing a lot of duplicated code, making it hard to maintain tests. To a certain extent this happens in every codebase I’ve ever seen. Test code has a different purpose than production code and as code becomes more complex tests become harder to write.
  • ««
  • «
  • 1
  • 2
  • 3
  • 4
  • »
  • »»
© Paytonrules Ramblings 2022