Asked by:
Unit testing - reference documentation

Question
-
User-1699898665 posted
Hi folks,
I've done a lot of testing in my time, but it's been mainly been the old fashioned, manual, way....and that works well. Looking into unit testing, specifically test driven development, more closely now and find that the documentation is either patchy (Selenium) or non existent (XUnit, MSTest)....well, so far as I cannot find it (yet?)
When I looked for documentation for XUnit I found this comment by Brad Wilson on 29/05/2019 that "The API documentation is contained in the XML doc comments (which ship with the library). They are surfaced via Intellisense." at this XUnit issue . So the authors/contributors have no intention of producing any kind of meaningful documentation or reference material. And I'm guessing this is the same across each of these tools. I'm not so concerned about Selenium which has been around a long time, has a lot of backup and a proper forum. However neither XUnit nor MSTest seem to.
So, I have two questions. Please bear in mind that I am no hobbyist...I do this for a job and keep things simple (especially for the complex work)....and I program both classic .NET and Core, typically MVC data with UI and integration projects.
- Would it be better to use MSTest than XUnit?
- Can anyone point me in the direction of something approaching a reference for one or the other?
Kind regards, Paul
Friday, October 9, 2020 10:56 AM
All replies
-
User475983607 posted
I've done a lot of testing in my time, but it's been mainly been the old fashioned, manual, way....and that works well. Looking into unit testing, specifically test driven development, more closely now and find that the documentation is either patchy (Selenium) or non existent (XUnit, MSTest)....well, so far as I cannot find it (yet?)TDD is a process for building testable code. XUnit and MSTest are unit test frameworks. Selenium is integration/automation test framework. These are all very different tools.
Unit testing is directly related to application design and code reuse. The code under test typically implement dependency injection and inversion of control (IoC) patterns. IoC is programming pattern for breaking code dependencies. It is very difficult to unit test code that is tightly bound to the UI. Adding unit tests to an existing project that has never had unit tests will require code rework. That's where Selenium is useful because Selenium runs automated tests from a UI perspective. These integration tests also exercises the business logic. The business logic is usually what you're unit testing.
Would it be better to use MSTest than XUnit?I use XUnit in Visual Studio and have no issues. I have used MSTest in the past. I like the testing features in XUnit so I went with XUnit in ASP.NET Core projects. Both frameworks are similar when it comes to organizing tests and using the test-runner in Visual Studio.
I think it is important to understand that a unit test is simply a project with classes and methods designed to test code blocks. For example, a C# class with methods and properties. The setup is standard project reference. The XUnit project references the project to test. This project contains the class(es) you wish to test. Then it is just a matter of exercising the class methods. The concept is pretty basic. Given these inputs I expect these results (assertations). If the assertions match the expected results then the test passes.
It's not clear what problem you are having with the documentation or unit testing in general. The most common issue is the code under test is tightly bound to the UI. Can you show an example unit test that is causing you trouble?
Can anyone point me in the direction of something approaching a reference for one or the other?Again XUnit and MSTest are unit test frameworks. Generally it is up to you or your team to pick a framework that has the feature you're looking for. I moved from MSTest to XUnit because I like the method annotations in XUnit.
Friday, October 9, 2020 12:13 PM -
User-1699898665 posted
it is up to you or your team to pick a framework that has the feature you're looking for.Thanks, but the problem I have is working out what these software's feature set is. By implication, you are saying that I and everyone else trying to learn this has to do that learning by trial and error.
Perhaps this is a relatively simple brick wall to head butt...but if I can climb over a wall using someone else rope I'd much rather do that.
Friday, October 9, 2020 1:19 PM -
User475983607 posted
PJM8765
By implication, you are saying that I and everyone else trying to learn this has to do that learning by trial and error.No.
PJM8765
Perhaps this is a relatively simple brick wall to head butt...but if I can climb over a wall using someone else rope I'd much rather do that.MSTest and XUnit integrate into Visual Studio and use the same test runner interface. I have experience with MSTest so moving to XUnit was very easy. The framework feature are different though. I simply read the official docs and the open source tests on GIT.
https://xunit.net/docs/comparisons
https://github.com/xunit/samples.xunit
Again, if you can share sample code that you are having trouble with would be very helpful.
Typically, testing frameworks are very simple to use within Visual Studio Right click on the class or method you wish to test and select Create Unit Tests. This creates templated testing code. The only gotcha is the class or method must be designed to for unit testing. This is usually the main issue because it requires proper upfront design.
If you follow a TDD process then you start by creating a class. Add the class to the test project either by right clicking (template) or manually depending on what you're doing. Next, add a class constructor. Test the constructor. If the test fails fix the issue and retest until the test is successful. Add a method. Test the method until the test succeeds. This type of information is available in the official docs.
https://docs.microsoft.com/en-us/visualstudio/test/unit-test-basics?view=vs-2019
Friday, October 9, 2020 2:18 PM