Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Reid - SCJP2 (April 2002)
Originally posted by Reid M. Pinchback:
MCC(Foo) = MCC(constructor)+MCC(methodA) = 5
WMC(Foo) = MCC(methodA)+MCC(methodB)+MCC(constructor) = 7
The problem is that WMC is treating every method as if it were a disconnected subgraph, and that isn't correct. The more methods you have in a class, and the more they call each other, the more WMC will diverge from MCC.
Note also that the MCC number does tend to correspond reasonably to the number of test cases required to achieve coverage.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
MCC(Foo) has its own problems, though - it doesn't take the size of an "edge" into account. I think I can write two methods of both MCC 1 with quite different complexity.
If you take the clients of the class into account, you might find that some methods don't need explicite testing.
Reid - SCJP2 (April 2002)
Originally posted by Reid M. Pinchback:
And how exactly does a WMC based on MCC constitute taking the size of an 'edge' into account?
There is also a gaping hole in the logic; if complexity is measured by a complexity algorithm of your choice, and two functions yield the same number, you can't then turn around and say they can have different complexity. You can say that different metrics measure complexity in different ways, but then obviously it is trivial to say that you can create two input examples such that metric A behaves differently than metric B.
Edge size is not relevant if you are trying to calculate testing effort (you either have a test that traverses the edge, or you don't... what is on actually on the edge does not change the minimal number of tests you need to exercise - i.e. cover - the code).
Obviously anybody can choose not to write a test (although from an XP or refactoring standpoint I bet that untested-because-it-is-unused code shouldn't even exist).
Choosing not to write a test is a separate issue from understanding the characteristics of a metric and the original motivation behind its creation.
MCC is a logical complexity metric that counts the minimal number of paths in code (in other words, ignores the dynamic complexity of recursion), and hence the minimum number of tests required to test that code (because unless you have a test to traverse a path, you haven't established that the path can work by exercising it). It isn't an isolated occurrence that the computation yields numbers with this correspondence, it is intentionally its fundamental nature.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Don't get me started about those stupid light bulbs. |