Silver Bullet to build superior software products

After contributing to open source projects development, I learnt that the superior quality of those products comes primarily because of the high quality unit tests those developers write. Applying same practice to enterprise software can also deliver superior quality products.

Suppose there is a function substring which returns a new string from the original string starting the index specified i.e.

public static String substring(String input, int beginIndex)

Example: substring(“unhappy”, 2) will return “happy”

Then following are the unit tests that I would write to exercise this function.

Test case #1 – Go Good

Goal: Validate the go good scenario

  1. Pass input string as “unhappy”
  2. Pass begin index as 2.

Expected Result: “happy” should be returned

Test case #2: Empty String

Goal: Validate empty String is handled gracefully

  1. Pass input string as “”
  2. Pass begin index as 2

Expected Result: “” (i.e. empty string) should be returned.

Test case #3: null String

Goal: Validate null is handled gracefully

  1. Pass input string as null
  2. Pass begin index as 2

Expected Result: null should be returned

Test case #4: Special Character String

Goal: Validate special string is handled properly

  1. Pass input string with special characters say: hi-!@#$%^&*()_+|”:<>?/
  2. Pass begin index as 2

Expected Result: “-!@#$%^&*()_+|”:<>?/” should be returned

Test case #5: begin Index 0

Goal: Validate begin index boundary condition is handled properly

  1. Pass input string as “unhappy”
  2. Pass begin index as 0

Expected Result: “unhappy” should be returned.

Test case #6: Negative begin Index

Goal: Validate negative begin index is handled properly

  1. Pass input string as “unhappy”
  2. Pass begin index as -1

Expected Result: IndexOutOfBoundsException should be thrown.

Test case #7: Large begin Index

Goal: Validate large begin Index than the string length is handled properly

  1. Pass input string as “unhappy”
  2. Pass begin index as 100

Expected Result: IndexOutOfBoundsException should be thrown.

Test case #8: Last Character begin Index

Goal: Validate boundary condition of begin index handled properly

  1. Pass input string as “unhappy”
  2. Pass begin index as 7

Expected Result: “” (empty String) should be returned

Test case #9: Concurrent Invocations

Goal: Validate there aren’t any racing condition in the implementation

  1. Fire 100+ threads to work on the same function concurrently.
  2. But each thread should be given different input parameters

Expected Result:

  1. All the 100 threads should return accurate results.
  2. None of them should result in exception.
Advertisements

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

Blog at WordPress.com.

Up ↑

%d bloggers like this: