Closed greenthepear closed 5 months ago
You can run tests by TestMain
:
type game struct {
m *testing.M
code int
}
func (g *game) Update() error {
g.code = g.m.Run()
return ebiten.Termination
}
func (*game) Draw(*ebiten.Image) {
}
func (*game) Layout(int, int) (int, int) {
return 320, 240
}
func TestMain(m *testing.M) {
g := &game{
m: m,
code: 1,
}
if err := ebiten.RunGame(g); err != nil {
panic(err)
}
os.Exit(g.code)
}
As the above solution seems enough to you, let me close this.
Operating System
What feature would you like to be added?
Debugging/testing tools to make snapshot testing easier, possibly by exposing some of the internal code used for /image_test.go.
Why is this needed?
Writing snapshot tests that work with
go test
for generated images is quite tricky because the game loop needs to be running forebiten.Image
methods like.At()
to be accessed. I had to open an issue for my framework to try to get some help.Projects that have achieved it mention how hard it is: https://github.com/tinne26/etxt/blob/main/testdata_generate.go - this file's comments are insightful about the subject:
With the number of frameworks and custom libraries people make for ebitengine, a simple way to make sure everything renders right I feel is a must.