You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
8 years ago
|
# Unity Test Tools # {#lua_unity_test_tools}
|
||
|
[TOC]
|
||
8 years ago
|
|
||
8 years ago
|
If you are using the [Unity Test Tools], FungusLua is a powerful and fast way to create integration tests using Lua scripting.
|
||
8 years ago
|
|
||
8 years ago
|
# Example # {#utt_example}
|
||
8 years ago
|
|
||
|
1. Create a new test in the scene.
|
||
8 years ago
|
2. Add a Lua object (Tools > %Fungus > Create > Lua) as a child of the test object.
|
||
8 years ago
|
4. In the LuaScript component, use the check() function to assert whatever conditions you need for the test. At the end, call pass().
|
||
|
|
||
|
Example test script:
|
||
|
```lua
|
||
|
-- Check a condition, and output a reason if it fails
|
||
|
check( myvar < 40, "My var is too big")
|
||
|
|
||
|
-- Just check a condition
|
||
|
check( myvar > 20 )
|
||
|
|
||
|
-- Test will exit successfully
|
||
|
pass()
|
||
|
```
|
||
|
|
||
|
If any of the checks fail, then the test fails immediately.
|
||
|
|
||
8 years ago
|
# Lua Functions # {#utt_lua_functions}
|
||
8 years ago
|
|
||
|
```lua
|
||
|
-- Checks if a condition is true
|
||
|
-- Lua has a built in assert function, so we called this check to avoid conflicting.
|
||
|
check(c, reason)
|
||
|
|
||
|
-- Pass an integration test
|
||
|
pass()
|
||
|
|
||
|
-- Fail an integration test
|
||
|
-- reason: Optional string explaining why the test failed.
|
||
|
fail(reason)
|
||
|
```
|
||
|
|
||
8 years ago
|
[Unity Test Tools]: http://u3d.as/65h
|