Secrets-of-Sosaria / World

Code repository for the Secrets of Sosaria world
GNU General Public License v2.0
11 stars 10 forks source link

(WIP) Add support for automated tests #124

Open maxsond opened 1 week ago

maxsond commented 1 week ago

Following a brief discussion on Discord and the enthusiasm towards the idea of automated tests but lack of knowledge in how to proceed, I thought I'd whip up something to spark some conversation.

The goal:

  1. Do not require a big lift (e.g. big refactor into a modern .Net app or something) to get started.
  2. Do not penalize the "production build" (the servers people are running) if test coverage increases (minimal performance loss/download size increase)

The core idea is pretty simple:

Some ideas/questions/concerns/areas for improvement:

  1. Right now I think it only detects code in the Source directory. I didn't have luck getting it to detect tests in the Items directory, but I'd like for the Data directory to be covered if I can figure out how.
  2. Maybe extend the output structure to incorporate an error message or some indication of which part of the test failed? Or perhaps keep it simple to encourage small tests?
  3. Does requiring the test methods to be static leave certain scenarios untestable? Should the attribute target be something different?
  4. Think about how to make mocking/stubbing lightweight for test-writers. Ideally any work there stays in the tests namespace and they just benefit from it without it becoming something that spreads its tendrils across the codebase. And ideally if/when new interfaces are created, mocking them doesn't require a lot of manual work. Seems like some sort of reflection sorcery should enable the automatic generation of delegates or something? Dunno, need to hack on that.
  5. All of this is being done with very minimal C# experience, so there are probably smarter ways to do things.
  6. Eventually, once all the test authoring stuff is good, the reporting should also be improved so a CI pipeline has something to pass/fail builds with. Right now my poor man's version of that is the output strings produced by Test.exe.