0

Does anyone know if NSpec or similar alternatives are still active?

Been in the Scala world for a little while recently and when I came back to C# I suddenly found the standard unit test style in C# really clunky.

I came across NSpec and really liked it. Seemed to give me the ability to write tests in the style offered by Typescript and Scala instead of the C# style i'm used to of :

  • [Test] When_CharacterAttacksOtherCharacter_OtherCharacterHealthGoesDownByAttackPower
  • [Test] When_CharacterAttacksOtherCharacter_OtherCharacterDiesWhenHealthBelow
  • [Test] When_CharacterAttacksOtherCharacter_AttackPowerIsMoreWhenTypeAdvantage

it let me write in this style

//context methods are discovered by NSpec (any method that contains underscores)
    void describe_BattleSystem()
    {
        //contexts can be nested n-deep and contain befores and specifications
        context["characters are in battle"] = () =>
        {
            before = () =>
            {
                ModifierRepository modifierRepository = new ModifierRepository();
                battleSystem = new BattleSystem(characterAttackPowerRepo, characterHealthRepo, characterTypeRepo, modifierRepository);
            };


            context["character attacks another character"] = () =>
            {
                before = () => battleSystem.Attack("Hero", "Ogre");
                
                it["defending characters' health goes down by attack character attack power"] = () =>
                {
                    battleSystem.GetHealth("Ogre").Should().Be(90);
                };
                
                it["other character dies when health below 0"] = () =>
                {
                    for (int i = 0; i < 100; ++i)
                        battleSystem.Attack("Hero", "Ogre");
                        
                    battleSystem.IsDead("Ogre").Should().Be(true);
                };
            };
        };
    }

Which I felt was a much nicer way to write tests.

But it seems NSpec was last updated 4 years ago. And I couldn't get the test runner to work at all. The IDE support seemed almost there:

Resharper test runner with NSpec

But I'm not sure if the .exes are out of date (following the manual steps doesnt work anymore) or if I missed something in the setup and i can't see how its going to unroll to the "It" level. the image above is from ReSharper I also tried it with visual studio with the VS extension and had the same issues.

Does anyone know if NSpec is still alive or if there has been a successor? or anything similar? I'm not really looking for full BDD here (like SpecFlow) What I feel is key is:

  • Being able to write tests in string form (get rid of those underscores)
  • Nesting tests into sensible units

Or if anyone has a way of doing the above in standard xUnit etc that I'm missing :)

For reference I've uploaded my tests to this git hub folder: https://github.com/chrispepper1989/RPGAsAService/tree/nspec_test/RPGAAS/RPGAAS/tests

It contains the original way I wrote the tests (in standard XUnit) and the NSpec version which I feel I prefer.

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
chrispepper1989
  • 2,100
  • 2
  • 23
  • 48

0 Answers0