I've always argued that the only easier way to test your code than using Visual Studio Test is to not test at all. But that doesn't mean that I think Visual Studio Test is perfect.
For example, the ExpectedException attribute, when placed on a test method, lets you check to make sure that your code throws the appropriate exception when something goes horribly wrong. The problem with ExpectedException is that it applies to the whole test method, not just the "code under test." This means that if your test or production code throws that exception anywhere at all, the ExpectedException attribute will tell you that your test has passed. Unfortunately, that exception may or may not have been thrown where you actually expected it to be thrown. That's not quite what you want to test for.
You have a better alternatives: the Assert object's ThrowsException and ThrowsExceptionAsync methods. With either of those methods, you specify the exception you expect to get from your method and then pass the code you want to test (as a lambda expression) to the method.
This example checks to see if the GetCustomer method throws a NullReferenceException when the GetCustomer method is called with an empty string:
Assert.ThrowsException<NullReferenceException>(() => cust = CustomerRepository.GetCustomer(""));
This test will now pass if (and only if) this call to the GetCustomer method throws a NullReferenceException. If any other code in my test method throws that exception (or if my code throws any other kind of exception), my test will be flagged as failed. And that's exactly what I want.
Posted by Peter Vogel on 11/16/2018 at 2:53 PM
Decision trees are useful for relatively small datasets that have a relatively simple underlying structure, and when the trained model must be easily interpretable, explains Dr. James McCaffrey of Microsoft Research, who provides step-by-step instructions and full source code.
Microsoft has open sourced an internal incubation project that can help developers integrate cutting-edge AI models quickly and easily into their apps.
Power Platform "is reinventing software development with AI-powered no-code development."
There are a raft of minor improvements for the brand-new Visual Studio 2022 v17.6 Preview 2, with accompanying release notes revealing that the IDE is ditching the baked-in Edge Developer Tools
Blazor QuickGrid is "built to be a simple and convenient way to display your data, while still providing powerful features like sorting, filtering, paging and virtualization."
> More Webcasts