Unit Testing of code refactoring
Code refactoring that does not change the original function under the premise of modifying the relationship between the code, simply to make the code more concise, easy to read, maintainability is higher, does not weaken the original function of the program. An important subject in the refactoring process is unit testing--ensuring that every step of the modification does not change the functionality of the program. In order to eliminate cumbersome coding, testing procedures, refactoring tools are essential, through refactoring tools, you can only write a small amount of code to do unit testing.
First, download and install the refactoring tool: ReSharper or other tools: Open the installation, online, ReSharper, extensions and updates, tools--, Visual Studio .
Install the UNit package: Opens a new project (class library), Visual Studio, right-click Solution, NuGet Package Manager, NUnit.
To add an existing item to a project, select the class to test.
Write the test code:
usingnunit.framework;namespacetestclasslibrary{[Testfixture] Public classtestfemalepatient {Privatefemalepatient _femalepatient; [Test] Public voidtestidealbodyweight () {DoubleExpectedresult =161.15626; DoubleRealresult =_femalepatient.idealbodyweight (); Assert.AreEqual (Expectedresult, Realresult); } [Test] Public voidtestdailycaloriesrecommended () {DoubleExpectedresult =1325.4; DoubleRealresult =_femalepatient.dailycaloriesrecommended (); Assert.AreEqual (Expectedresult, Realresult); } [SetUp] Public voidcreatefemalepatientinstance () {_femalepatient=Newfemalepatient (); _femalepatient.heightininches= the; _femalepatient.weightinpounds= the; _femalepatient.age= -; } }}
[Textfixtrue] indicates the unit to be tested
[Text] Decoration method for the method that you want to test
Right-click Project name, Run Unit Test
Green for passing test
Red for Test failed
Yellow for wait test
Unit Testing of code refactoring