How MC/DC Can Speedup Unit Test Creation

MC/DC is commonly used in avionics software development to guaranty safe flights and prevention of failures.

What is MC/DC?

Modified Condition/Decision Coverage, better known as MC/DC, is a code coverage criterion that satisfies the following:

  • Each decision takes every possible outcome.
  • Each condition is shown to independently affect the outcome of the decision.

Basic Definitions and Examples

Condition

Conditions are atomic components of a Boolean expression. Take note that conditions should be atomic, this means that it should not contain sub-expressions.

Decision

A Decision is composed of conditions, and zero or more Boolean operators. It is also the result of evaluating a Boolean expression.

Assumption(s)

Before anything else, let’s put on our assumption hat.

The Benefits and How it Works

  1. As mentioned, MC/DC will produce the optimal number of test cases for a certain Boolean expression. The optimal number will be at least n+1 cases; where n is the total number of atomic conditions. Once you know the total number of test cases to generate, then most likely, you can come up with minimal test functions while enjoying the benefits of high code coverage results.
  2. The test cases generated from the evaluation of MC/DC can also provide a high percentage of code coverage. The branch coverage, decision coverage and condition coverage are few of the main items being covered by MC/DC. It ensures that for a specific function, the majority of the logic and lines are being covered. Code reviewer will be happy to review your logic and shy away with your noncompliance to project metrics.
  3. When you already have the MC/DC results, you don’t have to worry too much about missed out conditional scenarios and at the same time, you avoid redundant test cases. Of course, there are certain cases that might require to check for the validity of the logic, then in that case you should consider adding more logical test cases to ensure correctness of logic. Because you already know what scenarios to consider, it saves you and others a great deal of time, wherein you can invest that time into more pressing matters.
  4. You can identify which conditions are not being evaluated. This helps developers identify which part of their codes are unreachable and non-executable. Avoiding costly reworks when moving the product to a higher environment.

The cost of fixing a defect detected during unit testing is minor compared to the cost (effort, time and humilation) of fixing a defect in user acceptance and live environments.

Considerations

There is an argument that MC/DC methodology is only applicable and effective to perfect functions. Perfect functions are functions whose logic are correct and have zero to no chance of failing. It exists only in a perfect world.

Conclusion

Learning how MC/DC works is a worthy investment for software development teams. A tool can also come in handy for large-scale/enterprise projects, where the number of conditions can go up to more than 20 (Yes! They exist – avionics and automotive industries. Some industries are getting complex also). It also comes in handy with other existing software development tools, which – in all honesty – can simplify the life of a developer.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arjay

Arjay

Software Development. Indie Hacker. Startups. Tech.