Recently has been improving the quality of coding, in order to ensure the quality, must have a set of weapons, Xunit.Net is such domineer sharp weapon.
How do I write unit tests
How can there be such a vulgar question? It’s not that you don’t want to write unit tests, it’s that you write unit tests, and then you Mock out a lot of test conditions every time. Sure, there are plenty of elaborate Mock tutorials out there, but none of them seem to solve my doubts. I was lucky to read a book about architecture interpretation, and its ideas are very good! Share with you:
The code that requires unit testing is actually logic written by the developers themselves, and testing the environment on which the logic depends is not the purpose of unit testing! Introducing logic into the environment access code only makes it harder to test, making it untestable. ** Therefore, only code that can be unit tested can be unit tested! ** Another way to determine testable code is to see if the method can be run directly with a main function. If so, it is code that can be unit tested. Another characteristic of testable code is that the parameters of the method unit can be simulated freely by the developer without relying on the external environment. Read this section of the I Ching, immediately solve the chest for many years of doubt.
Execute unit tests sequentially with Xunit
Xunit by default executes all unit tests in parallel, so it’s out of order!!
In general, it is not recommended to use the sequential way, there is actually a display of dependence, and will affect the number of failed (if the number is also assessed, do not use this method! Otherwise, at your own risk!)
The principle is to customize a sort execution algorithm: see the original example:Github.com/xunit/sampl…
Steps:
1. Copy custom properties and sort classes to the test project;
2, on the need to sort of test class increased [TestCaseOrderer (” FileServerUnitTest. PriorityOrderer “, “FileServerUnitTest”)]
Note: The first argument is the full name of the class and the second is the namespace. Write wrong not effective, no hint !!!!
[Fact, TestPriority(1)]
OK.