How can I unit-test my code?

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

How can I unit-test my code?

Post 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
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: How can I unit-test my code?

Post by SamuraiCrow »

There is an Assert() command built in in Hollywood for that purpose.
I'm on registered MorphOS using FlowStudio.
asrael
Posts: 31
Joined: Mon Jul 23, 2018 6:57 pm

Re: How can I unit-test my code?

Post 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
asrael
Posts: 31
Joined: Mon Jul 23, 2018 6:57 pm

Re: How can I unit-test my code?

Post 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.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: How can I unit-test my code?

Post 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.
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: How can I unit-test my code?

Post 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.
I'm on registered MorphOS using FlowStudio.
asrael
Posts: 31
Joined: Mon Jul 23, 2018 6:57 pm

Re: How can I unit-test my code?

Post 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.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How can I unit-test my code?

Post by airsoftsoftwair »

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