Content pipeline automation testing?

Hello folks!

Im trying to write tests for my custom content type. I wrote one for content importer an I am happy it works. Now I want to test writer and reader, but it turns out their methods are not public. So I can’t just create an instance of writer, feed it with content and verify the output.

Do you write tests for your content pipeline? If yes, then how do you set it up?

You can get access to non-public stuff through reflection. It’s a bit more annoying, but it’s doable.

Well, yes, but then the test would need tests itself. In such case it is probably makes more sense to just do manual testing. Besides, content loading is done every time I’m launching the game, so I assume bugs will be catched quickly.

I just thought maybe there is a way to setup pipeline within the test and somehow run it. But once I tried to do that myself, things become hairy pretty fast. So I think I’ll write tests just for importers and processors, because Import and Process methods are public and don’t require many dependencies. The rest will be tested manually.

I’m considering now an option to write a custom class that would implement reading and writing logic, and then just use this class within monogame’s ContentTypeReader/Writer. But even making simple ContentReader instance requires lots of parameters, but looks doable. I’ll try it.

UPD: Failed pretty soon. Creating instance of ContentReader/Writer is not possible because their constructors are internal. Well, screw it… I’ll just test manually.

You don’t have to use the MonoGame content pipeline. You can make your own stuff and use that instead. For example, here is one that I made a while ago: https://github.com/Apostolique/Apos.Content

At that point, doing tests is trivial.

1 Like