Page 1 of 1

Love testing framework?

Posted: Fri Apr 01, 2011 5:08 pm
by nyarly
Is there a preferred testing framework for Love scripts? I have some code I intend to reuse across projects, and might wind up releasing, but I really want to be able to test it to be confident in it's quality before I do that. I've already built some debug modes into game code so that I can see, e.g. that spritesheets are being loaded and indexed properly, but I'd really like to be sure that weird edge cases on vector math and in list handling don't bite me.

The other part of this question is: are there standard mocks for Love itself? I'm not really sure how I'd run a standard testing tool on my code and load up the real Love app at the same time. It's possible, maybe, that I could build a "game" that runs the tests, but that's tantamount to building a testing framework from scratch.

So, how about it? Any other TDD lovers around?

Re: Love testing framework?

Posted: Fri Apr 01, 2011 5:27 pm
by kikito
TDD lover here.

At the moment löve simply ignores testing. I mean, there's no assert_image_visible (x,y). The only way of testing right now is actually starting löve and doing a visual check.

In plain Lua, however, there are some facilities. I use telescope for testing middleclass. Others prefer luaunit.

Re: Love testing framework?

Posted: Fri Apr 01, 2011 5:34 pm
by genericdave
I've only had experience rolling my own rather trivial test suites by hand. Generally, however, I don't do test-driven-development. I do bug-driven-testing and a lot of the testing I do with my eyes.

Re: Love testing framework?

Posted: Fri Apr 01, 2011 9:53 pm
by EmmanuelOga
kikito wrote:TDD lover here.
In plain Lua, however, there are some facilities. I use telescope for testing middleclass. Others prefer luaunit.
I use telescope too. I try to isolate as much game logic as I can from the rendering/input part, and test just that logic (how cool would it be to be able to use the same game logic to do a curses version of your game, eh? ^^ .

For instance, in my columns game I only have tests for the logic of the board, finding matches, level loaders, etc.. but nothing for the actual rendering. So far, these are all the mocks I needed to make my tests run on the console:

Code: Select all

SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600

local fakeFont = function(name, size)
  return {
    getWidth = function(self, text) return #text * size end,
    getHeight = function(self, text) return size end,
  }
end

-- define fake love functions
love = {
  graphics = {
    getWidth = function() return SCREEN_WIDTH end,
    getHeight = function() return SCREEN_HEIGHT end,
    newFont = fakeFont,
  },
  audio = {
    setVolume = function() end
  }
}
You get the idea. Someone could go ahead and add mocks for each and every method of the love namespace, but I think it is better not to: by having incomplete mocks, you can first focus in trying to isolate the love/rendering code as much as you can. Once you get the limit of inconvenience/ugliness, you can just mock the method that is bothering alone.

Re: Love testing framework?

Posted: Sat Apr 02, 2011 9:10 am
by BlackBulletIV
kikito wrote:In plain Lua, however, there are some facilities. I use telescope for testing middleclass. Others prefer luaunit.
You can create your own telescope runner to work inside of Love. See this file for my implementation for the Grace tests repo (seriously outdated). Of course, it's really only possible to test logic, not display. The closest you can get to display is testing stuff like x/y coordinates and the like, but that's still logic.

As for my opinion on TDD, I find it an "at-times-necessary" chore. I've hardly ever done it, and I get bored really quick when doing it. But... I'll probably end up having to get used to it, and then like it, as I did with two space indentation; after all, the Ruby community are hooked on TDD.

Re: Love testing framework?

Posted: Sun Apr 03, 2011 6:51 pm
by nyarly
kikito wrote:TDD lover here.

At the moment löve simply ignores testing. I mean, there's no assert_image_visible (x,y). The only way of testing right now is actually starting löve and doing a visual check.
I've already done a spectrum of debug modes for the common stuff I've written - from a "debug" call on my spritesheet class, to a quickie test mode for particle effects. Over time, I'll probably build them up into something more formal - but they'd remain pretty tightly coupled to the code they're a part of.
kikito wrote: In plain Lua, however, there are some facilities. I use telescope for testing middleclass. Others prefer luaunit.
Cool. I was already looking at telescope, so I'm glad to have that confirmed.

Re: Love testing framework?

Posted: Sun Apr 03, 2011 8:25 pm
by miko
kikito wrote:TDD lover here.

At the moment löve simply ignores testing. I mean, there's no assert_image_visible (x,y). The only way of testing right now is actually starting löve and doing a visual check.

In plain Lua, however, there are some facilities. I use telescope for testing middleclass. Others prefer luaunit.
You may like calabash:
https://github.com/pib/calabash

Speaking of mocks, there is one you could extract from the lua-spec project:
https://github.com/mirven/luaspec/blob/ ... uamock.lua