Home > Programming > How would you test a library or API

How would you test a library or API

API or library cannot run by themselves so you need a host application to test the library. But in such case the test application itself might have bugs so you might not be reliably testing the library. So how would you test a library?

I think the following three will help:

1. Unit tests

– test developer writes code which invokes each of the public methods in the library and compares the result of the API to a preset expected result.

2. Stack trace

– If the library supports call tracing one could create a “goldenfile” listing the call stack observed when calling a particular public method of the library. In subsequent tests, any differences with this golden file will be treated as failures and shall be investigated.

3. Test hooks

– Test hooks help a lot when automating the tests. For example, in GUI test automation, if you add a special method which allows passing a “click” message to a button, the test developer can use this method in his automation code to simulate a click event.

 In my next article I will write about a design I am using to make my rich client applications testable.

Seshagiri

Advertisements
Categories: Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: