开发者

MSTest tutorials or walkthroughs [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expe开发者_如何学编程ct answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜