Rick Posted September 2, 2016 Share Posted September 2, 2016 Found a nice and easy lua unit testing framework and thought I'd share for anyone interested: https://github.com/bluebird75/luaunit You don't hear much about unit testing here but it can really help you write solid code and gives you a way to run all your tests after you make changes to make sure you didn't break anything. What I did: 1) Under the main game directory I created a UnitTesting folder 2) I downloaded and put lua5.1.exe in this folder (this is what LE uses) 3) Download the luaunit file (it's just one file) from the github link above 4) I Create test files in here named *.Tests.lua 5) Created a .bat file named RunAll.bat with the code below that will loop over all files with *.Tests.lua in them and run them piping the output to a file of the same name but with .txt at the end: echo off for %%f in (*.Tests.lua) do ( echo %%~f lua5.1.exe %%~f >> %%~f.txt ) I generally make "classes" like the AnimationManager.lua class and so I'm doing 1 lua test file per class that it's testing. An example of my lua test file is: luaunit = require('luaunit') dofile("../Scripts/BattleLibrary/Actor.lua") TestActor = {} function TestActor:testStaminaZero() local actor = Actor:Create(0, "Rick") luaunit.assertEquals(actor.stamina, 0) end os.exit(luaunit.LuaUnit.run()) 1 Quote Link to comment Share on other sites More sharing options...
mdgunn Posted September 3, 2016 Share Posted September 3, 2016 The thought of unit testing had been through my mind a few times (and just a few days ago actually) but not yet pursued it. This should help a lot. I hope to look at the Behaviour Tree stuff next time I do some AI http://www.leadwerks.com/werkspace/topic/14865-behaviour-tree/page__hl__behaviour. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.