NUnit的VS手动单元测试单元测试、NUnit、VS

2023-09-06 14:10:03 作者:把你满满下载到左心房

背景

我最近试图开发一套测试用于特定应用的回归测试。我一直在使用NUnit和有没有问题。

I have recently tried to develop a suite of tests for regression testing of a particular application. I have been using NUnit and have had no problems.

我跑进发送参数NUnit的测试,对于没有满意的回答似乎存在问题。

I ran into the issue of sending parameters to NUnit tests, for which no satisfactory answer seems to exist.

问题

说我实现一个简单的单元测试器加载一个类时,运行的启动,测试,和拆卸方法,顺序捕获异常,然后卸载组件。什么是这样做与使用NUnit的?

Say I implement a simple unit tester that loads a class, runs the Startup, Test, and Teardown methods in order, catching exceptions and then unloads the assembly. What are the downsides of doing this versus using NUnit?

在这种情况下,我可以很容易的参数传递给我的测试案例,或做其他任何疯狂的事情我可能会拿出。但我担心的是我从抛弃NUnit的损失。

In this scenario, I can easily pass parameters to my test cases, or do any other crazy thing I might come up with. But my concern is what I lose from abandoning NUnit.

推荐答案

你有什么损失呢?你的时间。

What do you lose? Your time.

如果您正在为一个客户或业务,它们是(presumably)付钱给你,以解决业务问题,而不是写的基础设施code。一些基础设施可能是必要的,以便处理业务需求。在这种情况下,显然不是。你重新发明轮子。

If you're working for a customer or business, they are (presumably) paying you to solve business problems, not to write infrastructure code. Some infrastructure may be necessary in order to address the business needs. In this case it's clearly not. You're reinventing the wheel.

不要掉进非我发明陷阱。使用NUnit的。它支持参数测试。如果NUnit的不能满足你的需求,调查 MbUnit的或xUnit.net 。或者看看 SpecFlow 等,为BDD风格。或者 FitNesse的验收测试。而这只是一个部分清单!

Don't fall into the Not Invented Here trap. Use NUnit. It supports parameterized tests. If NUnit doesn't meet your needs, investigate MbUnit or xUnit.net. Or look at SpecFlow, etc. for BDD-style. Or FitNesse for acceptance testing. And this is only a partial list!

如果你正在写你自己的一个测试框架,学习之用,太棒了!如果没有,你是在浪费你的时间和/或公司的钱。

If you're writing a test framework on your own for learning purposes, great! If not, you are wasting your time and/or your company's money.

解决技术方面的问题

JUnit的是在一个长的飞机行程。当时有没有很多替代品。编写一个测试框架是不是一个巨大的工程。写一个健壮一个是全功能的,易于使用的是比较困难的。写作测试运行,IDE集成,CI整合,code覆盖集成等是显著更加困难。而它已经完成的。除非你是Ayende Rahien,不这样做!

JUnit was originally created during a long airplane trip. Back then there weren't a lot of alternatives. Writing a testing framework is not a huge project. Writing a robust one that is full-featured and easy to use is more difficult. Writing test runners, IDE integration, CI integration, code coverage integration, etc. is significantly more difficult. And it's been done. Unless you're Ayende Rahien, don't do it!

除了整合,也失去了任何功能NUnit的不实现(也有很多)。我不使用所有这些,但我靠很多。

In addition to the integration, you also lose any features of NUnit you don't implement (and there are a lot). I don't use all of these, but I do rely on many of them.

(从我的意见移动)的