你怎么知道要测试的内容编写单元测试的时候? [英] How do you know what to test when writing unit tests?

查看:137
本文介绍了你怎么知道要测试的内容编写单元测试的时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#,我需要一个类称为用户,有一个用户名,密码,激活标记,姓,名,全名等应该有方法来验证和保存。难道我只是写的方法测试,做我甚至需要担心测试性质,因为它们是.NET的getter和放大器; ?setter方法​​

Using C#, I need a class called User that has a username, password, active flag, first name, last name, full name, etc. There should be methods to Authenticate and Save. Do I just write a test for the methods and do I even need to worry about testing the properties since they are .net getter & setters?

推荐答案

这许多伟大的反应也是对我的问题:的开始TDD - ???挑战解决方案的建议

Many great responses to this are also on my question: "Beginning TDD - Challenges? Solutions? Recommendations?"

我还建议考虑看看我的博客文章(这是部分灵感我的问题),我有上一些好的反馈。即:

May I also recommend taking a look at my blog post (which was partly inspired by my question), I have got some good feedback on that. Namely:

我不知道从哪里开始


  • 重新开始。只考虑编写测试,当你正在编写新
    码。这可能是旧的
    码重新工作,或者一个全新的功能。

  • 从简单的开始。不要去逃跑,并试图让你的头一轮
    测试框架,以及作为
    TDD式的。 Debug.Assert的正常工作。
    使用它作为一个起点。它没有
    乱用你的项目或创建
    依赖关系。

  • 开始积极。您正在试图改善你的手艺,感觉良好,
    吧。我见过很多开发商
    在那里,很高兴停滞
    ,而不是尝试新的东西,以更好地
    自己。你是做正确的
    的东西,记住这一点,它会帮助
    阻止你放弃。

  • 启动准备好了挑战。这是相当困难开始进入
    测试。期待一个挑战,但
    记住 - 挑战可以克服

  • Start afresh. Only think about writing tests when you are writing new code. This can be re-working of old code, or a completely new feature.
  • Start simple. Don’t go running off and trying to get your head round a testing framework as well as being TDD-esque. Debug.Assert works fine. Use it as a starting point. It doesn’t mess with your project or create dependencies.
  • Start positive. You are trying to improve your craft, feel good about it. I have seen plenty of developers out there that are happy to stagnate and not try new things to better themselves. You are doing the right thing, remember this and it will help stop you from giving up.
  • Start ready for a challenge. It is quite hard to start getting into testing. Expect a challenge, but remember – challenges can be overcome.

仅测试对于你的期望

我有真正的问题,当我第一次
开始,因为我经常坐在
那里试图找出每
可能出现的问题可能发生和
然后尝试测试它并修复。
这是一个快速的方法来头疼。
测试应该是一个真正YAGNI
的过程。如果你知道有一个
的问题,然后为它编写一个测试。
,否则,不要打扰。

I had real problems when I first started because I was constantly sat there trying to figure out every possible problem that could occur and then trying to test for it and fix. This is a quick way to a headache. Testing should be a real YAGNI process. If you know there is a problem, then write a test for it. Otherwise, don’t bother.

只测试一件事

每个测试用例应该永远只能测试
的一件事。如果你发现自己
把和测试案例名称,
你做错了什么。

Each test case should only ever test one thing. If you ever find yourself putting "and" in the test case name, you’re doing something wrong.

我希望这意味着我们可以从getter和setter动:)

I hope this means we can move on from "getters and setters" :)

这篇关于你怎么知道要测试的内容编写单元测试的时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆