我应该什么时候设计和记录我的测试用例?
在SDLC中,测试程序应该在实施后立即进行。然而,测试驱动开发鼓励我们在实现的同时进行测试。在我的讲座中,教授说测试用例应该是设计的一部分。
我是一名初级开发人员,为了实现一个新功能,我应该什么时候设计和记录我的测试用例?
我发现实现完之后再去测试所有的案例不太实际。因为一旦某个case失败了,我就得改代码,重新测试所有的case。还有其他方法可以克服和避免这种情况吗?我知道自动化测试是解决方案之一,但不知何故,自动化测试无法刺激所有测试用例,特别是涉及不同各方的集成测试用例。
另外,在我的测试用例中,我应该测试代码的所有部分吗?或者只是测试该功能请求的功能?或者这实际上取决于你有多少时间?
非常感谢。
IN SDLC, the Testing procedure should be right after implementation. However, Test-driven development encourages us to do testing while doing implementation. And in my lecture course, Prof said test cases should be part of the design.
I am a junior developer, to implement a new feature, when should I design and document my test cases?
I found that it is not so practical to test all the cases after finishing the implementation. It is because once a cases is failed, I have to change the codes and retest all cases again. Is there another way to overcome and avoid this? I know automated testes is one of the solution, but somehow, automated testes cannot stimulate all of the test cases, especially integration test cases which involves different parties.
Also, in my test cases, should I test all parts of the code? OR just test the functionality of that features request? OR it actually depends on how much time you got?
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题不太容易回答,因为正如你所说,“这实际上取决于你有多少时间。”不过,这里有一些意见:
实施后进行测试否
作为一名程序员,您是一种昂贵且稀缺的资源,并且有多个截止日期相互叠加。实际上,这意味着“从不测试”。实现了一段代码后,您将继续执行下一段代码,并意味着“当您有时间时”(您永远没有时间)回来编写测试。
还有你提到的问题。如果您在编写代码后进行了所有测试,并且您的测试发现了根本性错误,那么您必须返回并修复所有代码以及所有测试。
边实施边测试: 是的
一旦你掌握了节奏,这种方法实际上非常有帮助。您编写一些类,然后编写一些单元测试,并不断修改您的测试和代码,直到完成。我相信它实际上比在没有测试的情况下编写代码更快。
在处理大型项目时它也特别有帮助。运行单元测试来查看一个小模块是否正在工作是即时的。构建并加载整个应用程序以查看某个小模块是否正常工作可能需要几分钟的时间。它还可能会干扰您的注意力(至少需要 10 分钟)。
测试什么: 尽可能多
100% 的测试覆盖率可能永远不切实际。但一定要测试程序的关键部分,即执行数学计算或大量业务逻辑的部分。尽可能测试剩下的一切。没有理由测试“toString()”函数,除非它恰好对业务逻辑或其他东西至关重要。
另外,让你的测试尽可能简单,只有输入和输出。我的大多数测试函数都是两三行。如果您的函数由于组合太多而难以测试,则表明您的函数可能需要进行一些分解。确保测试边缘情况和“不可能”的场景。
Your question isn't so easy to answer, because, as you say, "it actually depends on how much time you got." Here are some opinions though:
Test after implementation: No
As a programmer, you're an expensive and scarce resource with multiple deadlines stacked up on top of each other. So effectively, this means "never test". After you've implemented one chunk of code, you will move on to the next chunk of code, and mean to come back to write tests "when you have time" (you never have time).
There are also the problems you mention. If you do all your testing after the code is written, and your tests discover something fundamentally wrong, you have to go back and fix all your code as well as all your tests.
Test while implementing: Yes
This method is actually really helpful once you get a rhythm for it. You write a bit of a class, then write a bit of a unit test, and continually revise your tests and your code until you're finished. I believe it is actually faster than writing code without tests.
It is also particularly helpful when working on a large project. Running a unit test to see if a little module is working is instantaneous. Building and loading your entire application to see if a little module is working may take several minutes. It may also interrupt your concentration (which costs at least 10 minutes).
What to test: As much as possible
100% test coverage is probably never practical. But absolutely test the critical pieces of your program, things that perform mathematical computation or lots of business logic. Test everything that's leftover as much as possible. There's no reason to test a "toString()" function, unless that happens to be critical to business logic or something.
Also, keep your tests as simple as possible, just inputs and outputs. Most of my test functions are two or three lines. If your function is hard to test because there are too many combinations, it's a sign that your function might need to be broken up a little bit. Make sure to test edge cases and "impossible" scenarios.
我的经验:
不进行测试所节省的时间永远无法弥补项目后期解决错误所花费的时间。一个合适的测试集总是会带来很大的回报。
My experience:
The time you save by not testing is never ever ever paying for the time you have to spent to solve bugs later in the project. A proper test set always pays a lot down the road, always.