Page 1 of 1

How can I unit-test my code?

Posted: Fri Aug 10, 2018 5:06 pm
by asrael
I'm a TDD guy.

I'd like to write tests-first. Is that possible?
I mean, I can write a simple framework myself, but maybe there is something?



Manfred

Re: How can I unit-test my code?

Posted: Sat Aug 11, 2018 3:48 pm
by SamuraiCrow
There is an Assert() command built in in Hollywood for that purpose.

Re: How can I unit-test my code?

Posted: Sat Aug 11, 2018 4:53 pm
by asrael
OK, so I create a separate script where I import my production code and use Assert().

Does 'luaunit' actually work? How far is Hollywood away from pure lua?


Manfred

Re: How can I unit-test my code?

Posted: Sat Aug 11, 2018 9:27 pm
by asrael
OK, I'm surprised. It works pretty well.
Very fast feedback loop. No big fuzz.

Using Classes as outlined in https://www.lua.org/pil/16.1.html. Works nicely.

Re: How can I unit-test my code?

Posted: Sat Aug 11, 2018 9:54 pm
by Bugala
Andreas can answer better, but to my understanding Hollywood is basically a heavily patched LUA. That there is great difference between them, but the very core is mostly same.

Re: How can I unit-test my code?

Posted: Sat Aug 11, 2018 10:02 pm
by SamuraiCrow
asrael wrote:
Sat Aug 11, 2018 9:27 pm
OK, I'm surprised. It works pretty well.
Very fast feedback loop. No big fuzz.

Using Classes as outlined in https://www.lua.org/pil/16.1.html. Works nicely.
Great! I started writing a framework for Hollywood once but ran into a roadblock with the include directory name being passed in as a constant and haven't gotten back to it for a while. All I currently have is an enumeration class and a unit test.

Hollywood is based on Lua 5.0.2, I think. The syntax is mostly different to make it readable to beginners.

Re: How can I unit-test my code?

Posted: Mon Aug 13, 2018 12:04 pm
by asrael
I think creating a simple TestCase base class that you can inherit from.
Under the convention to have test methods start with "test" and have "setUp" and "tearDown" methods defined, it should be simple to use 'reflection' retrieving all those methods and execute them.

That would make things a little simpler, because now I have to setup the 'class-under-test' in each test method, and have to execute each test method manually and the end of the script.

Re: How can I unit-test my code?

Posted: Fri Aug 17, 2018 11:41 pm
by airsoftsoftwair
For unit tests, the new @IF preprocessor command can also come in handy.