Love testing framework?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
nyarly
Prole
Posts: 2
Joined: Fri Apr 01, 2011 10:47 am

Love testing framework?

Post by nyarly » Fri Apr 01, 2011 5:08 pm

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?

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love testing framework?

Post by kikito » Fri Apr 01, 2011 5:27 pm

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.
When I write def I mean function.

User avatar
genericdave
Citizen
Posts: 53
Joined: Tue Dec 15, 2009 9:08 am

Re: Love testing framework?

Post by genericdave » Fri Apr 01, 2011 5:34 pm

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.

User avatar
EmmanuelOga
Citizen
Posts: 56
Joined: Thu Apr 22, 2010 9:42 pm
Location: Buenos Aires, Argentina
Contact:

Re: Love testing framework?

Post by EmmanuelOga » Fri Apr 01, 2011 9:53 pm

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.
--------------------------------------------------------------------------------------------------------
http://EmmanuelOga.com

User avatar
BlackBulletIV
Inner party member
Posts: 1260
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Love testing framework?

Post by BlackBulletIV » Sat Apr 02, 2011 9:10 am

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.

User avatar
nyarly
Prole
Posts: 2
Joined: Fri Apr 01, 2011 10:47 am

Re: Love testing framework?

Post by nyarly » Sun Apr 03, 2011 6:51 pm

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.

User avatar
miko
Party member
Posts: 409
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Love testing framework?

Post by miko » Sun Apr 03, 2011 8:25 pm

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
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 12 guests