开发者

How can I test my Java/Android code on a behaviour level?

I have recently noticed that my test code is too close to the production code. I notice that the test architecture (and the maintenance of it) draws a lot of time and energy from the actual product development while every change in the production code requires, at least, the same amount of effort (and risk!!!) in the test code. And what's worse is that I don't feel I get that much bang-for-the-buck.

What I would like to achieve is to test my code from a much higher level. I would like to verify the desired behaviour not necessarily test the implemented function.

I don't kn开发者_运维百科ow if you've noticed but the very best manual test cases explain what to verify not how to verify it. I feel that if I could write my automated tests according to the same paradigm, the actual test would be isolated from the current implementation and I would be assured that the quality of my test infrastructure doesn't degrade over time due to re-factoring caused by changes in the production code.

I guess I'm not that popular by now and I'm afraid my next coming thoughts won't make me more popular either:

I think most of modern testing (and now I'm talking about "industry modern" not "research modern") is taken to the extremes. We are expected to write test code that behave much like the Borg collective; the production code must be completely assimilated (resistance is futile :-) ), each and every cell and transistor must be tested by multiple tests (don't forget the negative test cases), preferably before implementation.

Yes, I might be exaggerating a bit, but only in the interest of making my point clear. Nevertheless: I don't think we're actually interested in what is happening in each single class or function. Most of us don't even bother to look at the test results for the individual functions as long as the class is tested "green". In the same manner I'm not sure I have the time to be interested in unit tests and alike as long as the behaviour of my code is verified to be predictable and expected.

So, what say ye? Am I walking down the wrong path? Is there a practical way of testing behaviour instead of functionality? And above all: Will I survive your wrath caused by this question?


Have you taken a look at BDD - Behavior Drivern Design/Development?

There are several very good tools helping you write stories and executing them against the code running the whole or parts of the app under test.

I have been using jBehave, but there are other tools, as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜