views:

80

answers:

2

Hi, I'm working on a project which I'm really not sure how to unit test. It's an unobtrusive tag based framework for wiring up events between models, views and delegates in a GUI system.

Basically you have one large json file which is used describes all of the events, event handlers and bindings. The user creates their models, views and delegates all of which have no knowledge of the framework. The JSON file is passed to an init() methods, then the framework creates all of the instances needed and takes care of all the bindings, listeners etc.

The problems I have are two fold:

1) There is basically only a single public method in the framework, everything else is communicated through the mark-up in the JSON file. Therefore I have a very small testing surface for what is a large and complicated application.

2) One of the big roles of the application is to instantiate class's if they haven't been instantiated previously and cached. This means that I need real classes in my test code, simple mocks aren't going to cut it.

At the moment I'm considering a couple if solutions. The first is start testing the private methods. The second is to just stub the constructors.

Any one else have any ideas?

+1  A: 

list the features (scenarios, use-cases, whatever you want to call them) of the system, and establish JSON data/frameworks for each feature. These are your unit tests.

Steven A. Lowe
By that I take it you mean make public the methods which handle specific part of the JSON, then write specs for them passing only the part of the JSON they're interested in?
ChrisInCambo
@[ChrisInCambo] I don't know to that level of detail Chris, I haven't seen your software! ;-) From your description, it sounded like the JSON data served as a general configuration for everything else, so model scenarios with that.
Steven A. Lowe
+2  A: 

1) There is basically only a single public method in the framework, everything else is communicated through the mark-up in the JSON file. Therefore I have a very small testing surface for what is a large and complicated application.

How is that possible? is this entire complicated framework stored in one class? if there are several classes involved, how do they share information without public methods?

A constructor is a public method too, by the way.

Are you just passing around the JSON object? that would couple your framework to the information source too tightly. You should have one class parsing the JSON, and the rest communicating without knowledge of the data source (via testable public methods).

Eran Galperin
The framework is controlled by mark-up not method calls, obviously there are private methods behind the scenes that are responsible for dealing with specific sections of that mark up. But the point is, I don't want users of the framework to have control via an API.
ChrisInCambo
I guess this boils down to should I start testing private methods to expand the testable surface?
ChrisInCambo
How does the class communicate its results? does it persists them, serialize them to disk, sends an http request?You should mock the interface of the output and see if you are getting the proper output for the proper input. Similar to what steven suggested.
Eran Galperin
Yes I think Steven is right, I would gain more from breaking the application up to allow a larger testing surface than I would from hiding it all behind a huge private closure.
ChrisInCambo