Ради вашего удобства наш сайт использует cookies! Узнать больше! Мы используем cookies

RimTest - Automated Testing Framework

Finally unit-testing in rimworld modding!

Write tests about how your mod is supposed to behave > Run the game > Check what failed exactly > Fix the bugs > Expand your mod efficiently and never have to retest the same thing twice anymore!

No need for hours of play testing to find bugs at every change you make, when you can just check everything in seconds!

Can also be used to detect and efficiently bug fix mod incompatibilities, just load mods and check what broke and how! -- assuming the mods are thoroughly tested of course

This is a testing framework with no impact on gameplay, this is compatible with everything.

First, add the RimTest.dll assembly as a reference for your mod.

Make sure to load your mod after RimTest in your About.xml:
<modDependencies>
<li>
<packageId>latrisstitude.rimtest</packageId>
<displayName>RimTest</displayName>
<downloadUrl>https://github.com/LaTrissTitude/RimTest/releases</downloadUrl>
<steamWorkshopUrl>https://steamcommunity.com/sharedfiles/filedetails/?id=2199316917</steamWorkshopUrl>
</li>
</modDependencies>
<loadAfter>
<li>latrisstitude.rimtest</li>
</loadAfter>

Template Test Suite to get you started:
using RimTest;
using static RimTest.Assertion;

namespace yourNamespace{
[TestSuite]
public static class RimTestSetup{
[Test]
public static void RimTestWorks(){
Assert(true).Not.To.Be.False();
}
}
}

The framework is documented, here's a cheat sheet to get you started:

Assert(value) followed as many grammar links you want among the following:

  • .Be
  • .Do
  • .Is
  • .Not *
  • .To
  • Not also negates your assertion, i.e Assert(x).Not.To.Be.Null() will fail the test if x is null, see below.

Then concluded by the comparison you want among the following:

  • .BetweenExclusive(min, max) ( min < value < max )
  • .BetweenInclusive(min, max) ( min <= value <= max )
  • .EqualTo( check ) ( value == check )
  • .GreaterThan( check ) ( value > check )
  • .LessThan( check ) ( value < check )
  • .SameAs( check ) ( value.Equals(check) )
  • .False() ( value == false )
  • .Null() ( value == null )
  • .True() ( value == true )

AssertFunc(function) follows the same grammar chain rules but only has access to the following comparison:

  • .Throw() ( fails if function throws an Exception when executed )

The GUI is now available as the mod settings screen!

Q: Why the extra work? By the time I'm testing things I'm usually done with my mod
A: You don't know what an update or another mod might break, or worse: Your mod could be going completely bonkers without ever crashing or throwing an error. Testing saves a lot of time by ensuring those situations don't happen, or allowing you to find multiple independent problems instantly.

Q: Unit tests don't find anything unexpected!
A: Of course, you can't detect bugs you were not looking for. However developping your mod around tests instead of the other way around makes it highly unlikely to actually miss bugs. And in the eventual case where you do find an untested bug, that's where you now can write a test to check it doesn't happen anymore! :D

Q: I don't have time to write tests
A: Then don't write tests for everything, it saves time in the long run, but it you can't test everything, test what you feel might be the most susceptible to break or what takes the most time to test manually.

Thanks to the helpful fellas from the Rimworld discord server and dubwise discord server for their handy help when I had some obscure bugs, you rock guys!

Ported to 1.3 by Sakura. This mod is currently unmaintained (I don't have time for modding anymore).