Talk about how to use Unity's Test Framework

In fact, Unity released this package a long time ago, but it feels that basically no one uses it. For such a good thing, with the attitude of letting everyone understand it, let’s talk about how it should be used today.

Step 1 Install it first, or update it to the latest.

 Step 2 Open the main window of the tool

Support unit testing in PlayMode or EditMode respectively, it depends on your needs

There is no difference between these two modes in writing code. The main difference is that PlayMode requires an editor to start, and the location of the unit test code is relatively free. EditMode requires you to create a special program for unit test code first. set out.

But the independence and security are better, and I personally feel that EditMode is better to use. Of course, this depends on personal preference.

In PlayMode, you only need to find your unit test class, double-click to execute it, and the green √ will appear if it passes.

 EditMode The first step is to create our dedicated assembly

 By default, a directory called Tests will be created in your currently selected location, which contains configured dependencies and referenced Tests.asmdef

 If there is no test file in your directory, it will give you a button to help you create one, and if there is, it will directly display the execution list

 After having the unit test file, the follow-up operation is exactly the same as that under PlayMode, and it can be executed by double-clicking.

There is no difficulty in writing unit test files. What needs to be paid attention to is the labels of 2 namespaces and 2 test methods. The [UnityTest] method is different from the ordinary c# method. It is a coroutine method.

The above is how to use the Test Framework package. It is recommended that teams with time and energy should use it.

 

 

 

Guess you like

Origin blog.csdn.net/WPAPA/article/details/128355306