在单个测试中检查几个不同的示例输入? [英] Check several different example inputs in a single test?

查看:47
本文介绍了在单个测试中检查几个不同的示例输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想编写一个验证电子邮件地址的函数用正则表达式.我写了一个小测试来检查我的函数并编写实际功能.让它通过.

Let's say I want to write a function that validates an email address with a regex. I write a little test to check my function and write the actual function. Make it pass.

然而,我可以想出一堆不同的方法来测试相同的函数(test@test.com;test234@test.com;test.test.com 等).

However, I can come up with a bunch of different ways to test the same function (test@test.com; test234@test.com; test.test.com, etc).

我是否将所有需要检查的咒语都放在同一个单使用多个 ASSERTS 进行测试,或者我是否为每个 ASSERTS 编写一个新测试我能想到什么?

Do I put all the incantations that I need to check in the same, single test with several ASSERTS or do I write a new test for every single thing I can think of?

谢谢!

推荐答案

大多数测试框架现在都支持某种基于数据的测试,让您可以在多个数据集上运行相同的测试.

Most testing frameworks now support some sort of data based testing to let you run the same test on multiple data sets.

请参阅 NUnit 中的 ValuesAttribute.

See the ValuesAttribute in NUnit.

xUnit.net、MBUnit 等也有类似的方法.

xUnit.net, MBUnit and others have similar methods.

这篇关于在单个测试中检查几个不同的示例输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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