MSTest 教程或演练

发布于 2024-10-05 11:56:30 字数 104 浏览 1 评论 0原文

我正在尝试掌握 MSTest。我正在将 VS2010 与实体框架 4 一起使用 - 这并不是特别重要。我在网上搜索了教程,但没有找到任何有用的东西。我正在使用域模型,这在示例方面是否有任何区别?

I'm trying to get to grips with MSTest. I'm using VS2010 with entity framework 4 - not that that's particularly important. I've scouted the web for tutorials but haven't found anything that useful. I'm using a domain model if that makes any difference in terms of examples?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话墙 2024-10-12 11:56:33

最简单的开始方法是下拉“新建”菜单项,单击项目,然后选择“测试项目”。在您当前的解决方案中正确执行此操作,以便轻松访问主项目。接下来,进入您的原始项目,右键单击并选择“创建单元测试”。这将出现一个对话框,您可以在其中选择要测试的方法以及要使用的测试项目(默认为新创建的测试项目)。当您“开始”时,您将看到一个新的测试类,其中充满了测试方法。一开始这可能有点令人困惑,但如果您只是专注于运用您的方法并评估结果,那么它应该很快就会非常清楚。

请注意,所有评估都经过“Assert”类;您只需根据预期值和实际值测试“AreEqual”、“IsTrue”等内容。例如:

  Assert.AreEqual(120, bpi.Cholesterol);
  Assert.IsTrue(bpi.HighTriglyceride);

当 IDE 创建测试文件时,它将创建一个具有四种方法的区域:一种在创建测试类之前运行(静态),一种在每次测试之前运行,一种在每次测试之后运行,以及完成后清理的一个。这里重要的是属性,而不是方法名称。

完成测试后,使用(新添加的)测试按钮运行单个测试(光标所在的测试)或测试项目中的所有测试。您将看到弹出的结果,并且您将开始掌握从这里开始的方向。

随着时间的推移,当您编写越来越多的测试时,您会发现测试列表等的用途,但这将让您现在开始。

The easiest way to get started is to pull down the "New" menu item, click project and then select a "Test project." Do this right in your current solution so it will be easy to gain access to the main project. Next, go into your original project, right-click on a Class and select "Create Unit Tests." This will result in a dialog in which you can select which methods to test and the testing project you wish to use (which will default to your newly created Test Project). When you "go" you'll see a new testing class replete with testing methods. This might be a bit confusing at the beginning but if you just focus on exercising your methods and evaluating the results then it should be pretty clear pretty quickly.

Note that all evaluations go through the "Assert" class; you'll just test for things like "AreEqual", "IsTrue", etc. based on an expected value and an actual value. For example:

  Assert.AreEqual(120, bpi.Cholesterol);
  Assert.IsTrue(bpi.HighTriglyceride);

When the IDE creates the testing file, it will create a region with four methods: one that is run before the test class is created (a static), one that is run before each test, one that is run after each test, and one that cleans up after you are done. The attributes are what are important here - not the method name.

When you've finished your tests, use the (newly added) testing buttons to run either an individual test (the one where your cursor rests) or all of the tests in the testing project. You'll see the results pop up and you'll start getting a handle on where to go from here.

In time, as you write more and more tests, you'll find uses for the tests lists, etc. but this will get you started for now.

梦幻的心爱 2024-10-12 11:56:33

您可能会更幸运地找到 NUnit 示例。幸运的是,NUnit 中的大部分功能都可以在 MSTest 中复制,而无需太多麻烦。

You may have better luck looking for NUnit examples. Fortunately, most of the functionality in NUnit can be replicated in MSTest without too much hassle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文