How can I unit-test my code?

Discuss any general programming issues here
Post Reply
asrael
Posts: 20
Joined: Mon Jul 23, 2018 6:57 pm

How can I unit-test my code?

Post by asrael » Fri Aug 10, 2018 5:06 pm

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

SamuraiCrow
Posts: 171
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: How can I unit-test my code?

Post by SamuraiCrow » Sat Aug 11, 2018 3:48 pm

There is an Assert() command built in in Hollywood for that purpose.

asrael
Posts: 20
Joined: Mon Jul 23, 2018 6:57 pm

Re: How can I unit-test my code?

Post by asrael » Sat Aug 11, 2018 4:53 pm

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

asrael
Posts: 20
Joined: Mon Jul 23, 2018 6:57 pm

Re: How can I unit-test my code?

Post by asrael » 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.

Bugala
Posts: 691
Joined: Sun Feb 14, 2010 8:11 pm

Re: How can I unit-test my code?

Post by Bugala » Sat Aug 11, 2018 9:54 pm

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.

SamuraiCrow
Posts: 171
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: How can I unit-test my code?

Post by SamuraiCrow » Sat Aug 11, 2018 10:02 pm

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.

asrael
Posts: 20
Joined: Mon Jul 23, 2018 6:57 pm

Re: How can I unit-test my code?

Post by asrael » Mon Aug 13, 2018 12:04 pm

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.

User avatar
airsoftsoftwair
Posts: 2557
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: How can I unit-test my code?

Post by airsoftsoftwair » Fri Aug 17, 2018 11:41 pm

For unit tests, the new @IF preprocessor command can also come in handy.

Post Reply