Unit testing in software development is a very important link, =. = Plate face Go to a few companies have no unit testing this concept. Although our system is separated from the code, in most cases we need to rely on other modules to run. (The Unit test section teaches me to solve this problem.) Although I learned the unit test, I believe the actual process is not used. Next I'll show you a little bit about how unity does unit testing. (Recommended book "Second edition of Unit Test Art")
Why Use unit tests:
1. We can get the game modules we write from the Unit test portal (instead of running into our module directly in Unity)
2. Write unit tests uniformly in one place, resulting in the test code not being scattered
3. There are many advantages, (the use of unit tests is likely to cause delays in project progress)
Test framework:
1. C # NUnit very good framework (requires download of two plugins in Visual Studio)
Templates is a template for creating a project, and you can create a test project in Visual Studio after installation
Test Adapter is the debug window
1. Unitytesttools (The framework has extended the Unity window, the test is done directly in the Unity window (similar)), Assetstore can be down to
Start introducing the basic use of the NUnit framework:
First we create a console program called Unit Test Project, then create nunit test project (called Nunit.test1)
We make a file suffix validation module, where a fileverify verifies that the suffix name is legal (TXT). Next, create a fileverify class in the console project with a
The Isfilenameendtxt method verifies whether the string ends with a txt, returns true, and does not return false
Public classfileverify {//Verify that the file suffix is not txt Public BOOLIsfilenameendtxt (stringfileName) { if(Filename.endswith (". txt")) return true; Else return false; } }
Next look at our NUnit project, he has helped us to create a class (TestClass), which already has a method TestMethod (). Now we don't need to write any code, click on the menu bar-----Test Explorer, Windows----like:
Click on all to run, TestMethod test success.
Next we write the unit test of the Test Fileverify.isfilenameendtxt () method in TestMethod, and we first think of passing in 1.txt and txt. Two strings. Your project is to be created
Fileverify class must be NUnit project into the console project
[Testfixture] Public classTestClass {[Test] Public voidTestMethod () {fileverify F=Newfileverify (); BOOLIsresult = F.isfilenameendtxt ("1.txt"); Assert.istrue (Isresult); Isresult= F.isfilenameendtxt ("txt."); Assert.istrue (Isresult,"here's an error."); } }
We're running the test (it's going to fail here because "txt.") Returned is false), encountered a asset.isture (false) throw exception
How is unit testing debugged?
Select Single test, Debug checked test
Here you have learned how to conduct a unit test! ()
==============================================================================
Unity Unit Test (Nunit,unitytesttools)