mstest

Unit Test Assert.AreEqual failed

醉酒当歌 提交于 2019-12-01 16:43:46
I have a unit test for a method which gets an object from a collection. This keeps failing and I cannot see why, so I have created a very simple test below to create 2 supplier object and test they are equal to see if I can spot the problem in my test of my code. But this test again is failing. Can anyone see or explain why? [TestMethod()] public void GetSupplierTest2() { Supplier expected = new Supplier(); expected.SupplierID = 32532; expected.SupplierName = "Test 1" Supplier actual = new Supplier(); actual.SupplierID = 32532; actual.SupplierName = "Test 1" Assert.AreEqual(expected, actual);

Testing ASP.NET MVC website

拟墨画扇 提交于 2019-12-01 16:32:02
问题 I'm working on an MVC site with an image upload capability and I want to write a test that will upload an image. I made an image called TestImage.jpg and set Copy to Output to be "Copy if Newer". In my test I try to load that with the following code: System.Drawing.Image testImage = System.Drawing.Image.FromFile(@"TestImage.jpg"); Shouldn't the "Copy to Output" copy it to the same directory where the test is running? If not, how can I find out where it was copied to? Best would be some kind

Make MSTest respect [Conditional()] attribute?

旧巷老猫 提交于 2019-12-01 16:13:45
问题 I'm using VS2010, I have the following method call: [Conditional("DEBUG")] public void VerboseLogging() { } public void DoSomething() { VerboseLogging(); Foo(); Bar(); } Then I have a unit test for the DoSomething method which checks that it emits proper logging. [Conditional("DEBUG"), TestMethod()] public void EnsureVerboseLog() { DoSomething(); VerifyVerboseLoggingCalled(); // <-- fail in release builds since VerboseLogging() calls get eliminated. } It seems that MSTest only sees TestMethod

Code coverage for async methods

限于喜欢 提交于 2019-12-01 15:34:42
When I analyse code coverage in Visual Studio 2012, any of the await lines in async methods are showing as not covered even though they are obviously executing since my tests are passing. The code coverage report says that the uncovered method is MoveNext , which is not present in my code (perhaps it's compiler-generated). Is there a way to fix code coverage reporting for async methods? Note : I just ran coverage using NCover, and the coverage numbers make a lot more sense using that tool. As a workaround for now, I'll be switching to that. This can happen most commonly if the operation you're

ExcludeFromCodeCoverage Isn't Working in VS2012

冷暖自知 提交于 2019-12-01 15:16:29
I have a class in my code that I don't want showing up in code coverage numbers. I added the [ExcludeFromCodeCoverage] attribute to the class definition like this: [ExcludeFromCodeCoverage] public class MyClass { ... } According to the docs ( http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.aspx ) this should be all I need, but the class still shows up in code coverage analysis. I'm using VS2012/.NET 4.5 if that matters. Any ideas why this wouldn't work? Here's what was going on, and here's how I fixed it. I was using a .runsettings file

What is the usage of Assert.Equals? [closed]

怎甘沉沦 提交于 2019-12-01 15:00:53
I am working on Unit Testing for my current project and came across something odd. The .Net UnitTesting library has both Assert.Equals and Assert.AreEqual. The remarks for Assert.Equals say to use Assert.AreEqual to compare two objects, but gives no reason as to why to do so over Assert.Equals. Can somebody explain when you should use Assert.Equals in unit testing, if ever and the difference between Assert.Equals and Assert.AreEqual? Assert.Equals is just the Equals method inherited from object . It has nothing to do with unit testing, and in fact, has no use. To be more precise, Assert.Equals

ExcludeFromCodeCoverage Isn't Working in VS2012

大憨熊 提交于 2019-12-01 14:10:46
问题 I have a class in my code that I don't want showing up in code coverage numbers. I added the [ExcludeFromCodeCoverage] attribute to the class definition like this: [ExcludeFromCodeCoverage] public class MyClass { ... } According to the docs (http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.aspx) this should be all I need, but the class still shows up in code coverage analysis. I'm using VS2012/.NET 4.5 if that matters. Any ideas why this

Unit-testing IList with CollectionAssert

守給你的承諾、 提交于 2019-12-01 13:58:32
问题 The MSTest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparently a list is not a collection.. Are there ways to make my IList an ICollection? 回答1: You could call the ToArray() extension method on it - Array implements ICollection Edit: Also, while List<T> implements ICollection, IList<T> only implements ICollection<T> which does not implement ICollection, so if you know the item in the test is a List<T> , you should be able to cast it... 回答2: You

What is the usage of Assert.Equals? [closed]

拟墨画扇 提交于 2019-12-01 13:49:52
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect 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 6 years ago . I am working on Unit Testing for my current project and came across something odd. The .Net UnitTesting library has both Assert.Equals

MSTest - Run “LoadTests” and Write Results to SQL Server Database

血红的双手。 提交于 2019-12-01 12:16:57
If you want to configure your VS "Load Tests" to write the results to a database server, you use the following instructions . If you want to run your "Load Tests" through powershell on a separate machine( think TFS 2018 release step ), you use the following instructions . I would like to do both, on multiple machines, in a automated manner, but there's not a great deal of documentation on this, I can run my tests like this: .\mstest /testcontainer:"C:\XXX\ABC.loadtest" But the results are kicked out to a "TRX" file rather than being placed into a database( there is some discussion on this ).