The evolution of Unit Testing Syntax and Semantics

The semantics of how you write a unit test, the basic syntax, or Domain Specific language of how we write them, has been relatively stale for quite some years now.  But under the covers, the syntax revolution seems to be brewing, as people try to come up with newer, hopefully better and more readable syntaxes for tests and specifications that become more and more complex as the current Agile community struggles to accept best practices in this arena.

I'm guilty of that too, but a recent post by Jeremy Miller prompted me to try and list all the different syntax variations I've come across in the .net and some in java world (not necessarily in chronological order). Most ofthese didn't necessarily catch on as de facto standards, but are real world attempts to make a better world or explore new horizons.

POUT (Plain Old Unit Test) Syntax

  • JUnit initial syntax
  • Attributes: NUnit with attribute syntax, removing inheritance and test naming requirements
  • Extensibility: MbUnit is extensible testing framework with lots of powerful attributes.
  • Naming conventions for unit tests seem to be something people are actively looking for.
  • Simplicity is back: XUnit tries to go back to basics: No setup\teardown, different attribute names.  
  • Fluent: My implementation of NRehersal uses delegates and a more fluent interface for tests

Mocking

  • Mocks Vs. Stubs: The Difference is explored (here too) and makes its way into some of the mock frameworks (NMock, JMock, Rhino.Mocks)
  • Explicit (reflection based) mocking statements such as (New DynamicMock(typeof(Interface), mock.Expect(...))
  • Record-replay syntax from Rhino.Mocks, EasyMock, TypeMock and others
  • fluent mocking APIs into our tests (NMock2)
  • Auto Mocking Containers (introduced by Elutian) will use RhinoMocks and Ioc Containers under the test covers (back to base classes)
  • Mocking the Un-Mockable: TypeMock (and JMockIt on the java side) introduce the possibility of mocking production code that is currently untestable without needing to refactor it.

BDD, Specifications and other Domain Specific Languages

I'm probably forgetting a few here, so let me know in the comments.

So, we see a nice evolution from beginner style to bdd and spec style. lots of work on the syntax is done, but there is currently lots of chaos. Think Blue-Day Vs. HD-DVD, only with about 5 main competitors. The nice thing about this: The community will decide what worls, so it would be interesting to see where we are one year or a two years from now in relation to this list!

Published Thursday, January 17, 2008 6:21 AM by RoyOsherove

Comments

Thursday, January 17, 2008 8:15 AM by Nat

# re: The evolution of Unit Testing Syntax and Semantics

Don't forget simple good programming.  In my experience, simply refactoring your tests as you write them, to remove duplication and better express intent, produces high quality test code and doesn't require ever more complex tools.

E.g. nat.truemesh.com/.../000714.html

Thursday, January 17, 2008 9:31 AM by Jimmy Bogard

# re: The evolution of Unit Testing Syntax and Semantics

Here's some updates:

RBehave is merged into RSpec, so RSpec includes a story runner now

NUnit.Behave and NSpec have merged into NBehave, which now includes specs and story runner.

Spectre is a BDD framework written in Boo (specter.sourceforge.net).

Scott is also working on something, but I don't know if it's public yet.

# Reflective Perspective - Chris Alcock » The Morning Brew #13

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #13

Saturday, January 19, 2008 7:48 PM by Patrik

# re: The evolution of Unit Testing Syntax and Semantics

I wrote an article a couple of weeks back about a pattern that I use when I do unit testing in .Net. It allows for access of non public fields in the tested class making it easier to install test doubles in the class while not having to alter the public interface of the class. Please check it out at: ondevelopment.blogspot.com/.../unit-testing-pattern.html

Sunday, January 20, 2008 8:56 AM by Steve Freeman

# re: The evolution of Unit Testing Syntax and Semantics

An interesting start.  I'm not sure about the chronology. The first was SUnit (Smalltalk) and I think we're still trying to get back to that degree of simplicity. That's also where the test name convention came from which some of us think is unnecessary.

As always happens, most of the ideas were there very early on, but not widely understood. Much of the subsequent work has been to do with clarification rather than radical new concepts.

# Chile ??gil » Blog Archive » La evoluci??n de la sintaxis y semantica en las Pruebas de Unidad (Unit Testing)

Pingback from  Chile ??gil  » Blog Archive   » La evoluci??n de la sintaxis y semantica en las Pruebas de Unidad (Unit Testing)

Thursday, February 14, 2008 6:13 PM by ISerializable - Roy Osherove's Blog

# Future of Mock Frameworks: AEIS - Abstract Expectations & Isolation Syntax

As I was looking back and forward on the changing syntax of testing and mock frameworks, it occurs to

Thursday, March 13, 2008 5:10 AM by Testid on ilusad « Beautiful code

# Testid on ilusad « Beautiful code

Pingback from  Testid on ilusad « Beautiful code