Unity3d Official Unit Test plugin Learning

Source: Internet
Author: User

More Unity3d Experience:Unity3d experience sharing

Unity has long been supported by unit tests, as seen in the unittest option of the mono editor and the NUnit.dll in the installation directory. Only few people in the country studied it.

This time took the test plug under the Assertstore research, summed up a set of feasible solutions

https://www.assetstore.unity3d.com/#/content/13802

Children's shoes, which have not been used in unit testing before, can be used in the unit test of vs to download a vs2012

This plugin is divided into 2 test modes, Unit test unittest and integration test integration

One drawback of unit test mode is that it can only be run in the editor state. You can use a lot of editor's things, but can not run the state means that does not support ngui,playmarker and so on.

Integration testing calls Unity's running functions and then runs the test cases one by one. is equivalent to the actual game running environment, so it is generally used for integration testing

Integration testing is divided into 2 types, dynamic integration testing and general integration testing

The following will be explained

1. After the plugin is downloaded, the examples second is an example of integration testing.

2. One more tab, then open the Integration Test panel

3. Each integration test needs to be judged by the asserted component.

4. After the test is complete, the test panel will be labeled in the Hierarchy panel. (The callback that is tied to the hierarchy shows that the playmarker ' play ' word is gone--)

This common integration test is typically used to render visible if the y-coordinate is less than 5. But there's a lot of restraint

Calling a function is cumbersome and cannot be assert.istrue (...) like vs. So we're going to use dynamic integration testing.

5. Examples of dynamic integration testing here, you can see how the DynamicIntegrationTest.cs script is written.

usingSystem;usingSystem.Collections.Generic;usingUnityengine; [Integrationtest.dynamictestattribute ("exampleintegrationtests")]//the scene name of the binding//[Integrationtest.ignore][Integrationtest.expectexceptions (false,typeof(ArgumentException))] [Integrationtest.succeedwithassertions] [Integrationtest.timeoutattribute (1)][integrationtest.excludeplatformattribute (Runtimeplatform.android, Runtimeplatform.linuxplayer)] Public classdynamicintegrationtest:monobehaviour{ Public voidStart () {integrationtest.pass (gameobject); }}

6. Test script, first feature Dynamictestattribute ("..") is the scene name of the binding. If the scene is under the name, the dynamic test script is automatically mounted to the test panel. It's more comfortable to use.

[Integrationtest.dynamictestattribute ("exampleintegrationtests")][integrationtest.excludeplatformattribute (Runtimeplatform.android, Runtimeplatform.linuxplayer)] Public classtest1:monobehaviour{ Public voidStart () {Integrationtest.assert (gameobject); }}[integrationtest.dynamictestattribute ("exampleintegrationtests")][integrationtest.excludeplatformattribute (Runtimeplatform.android, Runtimeplatform.linuxplayer)] Public classtest2:monobehaviour{ Public voidStart () {Integrationtest.assert (gameobject); }}
View Code

7. In such a. cs file, create a number of test classes. Then for different modules, divided into different test scenarios, to test. Can

This can also support many plugins such as Ngui. Nothing but some button response events force a call with reflection.

Unity3d Official Unit Test plugin Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.