{"__v":6,"_id":"54485515c1b42e08005b82bd","category":{"__v":5,"_id":"5447ed118d7af31a00dd411c","pages":["54485515c1b42e08005b82bd","5447ed4d8d7af31a00dd411d","5447ef460319802200fc070d","54485571c1b42e08005b82c1","54af53eb0cf42a0b001d5b73"],"project":"54471fc9e12a270800028adc","version":"54471fc9e12a270800028adf","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-22T17:44:49.648Z","from_sync":false,"order":3,"slug":"assertions","title":"Assertions"},"is_link":false,"project":"54471fc9e12a270800028adc","user":"54471f91beb6320800da6f75","version":{"__v":10,"_id":"54471fc9e12a270800028adf","project":"54471fc9e12a270800028adc","createdAt":"2014-10-22T03:08:57.750Z","releaseDate":"2014-10-22T03:08:57.750Z","categories":["54471fc9e12a270800028ae0","5447b9e7b96a63140077d747","5447be130319802200fc0620","5447ed118d7af31a00dd411c","5447ed230319802200fc0702","5448524c4544c30800241f41","544854504544c30800241f4d","544854af4544c30800241f50","544854e74544c30800241f51","54485557c1b42e08005b82bf"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["545ea8b77e32310e00f400e0"],"next":{"pages":[],"description":""},"createdAt":"2014-10-23T01:08:37.117Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"basic_auth":false,"results":{"codes":[]},"try":true,"auth":"never","params":[],"url":""},"isReference":false,"order":0,"body":"The [Should library](https://github.com/erichexter/Should) gives developers an expressive way to assert the expected outcome of a test.\n\nInstead of writing assertions like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Test]\\npublic void then_it_credits_the_account()\\n{\\n     Assert.Equals(15.63, _accountBalance);\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nThe library provides extension methods that make assertions read more like English and thus are more friendly for humans:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Test]\\npublic void then_it_credits_the_account()\\n{\\n     _accountBalance.ShouldEqual(15.63);\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nBelow are some examples of extension methods provided by the Should library.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"_account.ShouldBeNull();\\n_account.ShouldNotBeNull();\\n_account.ShouldBeType<Account>();\\n_account.ShouldNotBeType<Vehicle>();\\n\\n_purchaseConfirmation.ShouldEqual(\\\"Your purchase completed successfully\\\");\\n_purchaseConfirmation.ShouldNotEqual(\\\"Your credit card was declined\\\");\\n\\n// Booleans\\n_transactionCompleted.ShouldBeTrue();\\n_transactionCompleted.ShouldBeFalse();\\n\\n// Strings\\n\\\"This could be a really long string\\\".ShouldContain(\\\"really long string\\\");\\n\\\"This could be a really long string\\\".ShouldNotContain(\\\"something that shouldn't be here\\\");\\n\\\"This string contains text\\\".ShouldNotBeEmpty();\\n\\n// Lists\\n_tags.ShouldContain(\\\"Green\\\", \\\"Blue\\\");\\n_tags.ShouldNotContain(\\\"Yellow\\\");\\n_tags.ShouldBeEmpty();\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"the-should-library","type":"basic","title":"The Should library"}

The Should library


The [Should library](https://github.com/erichexter/Should) gives developers an expressive way to assert the expected outcome of a test. Instead of writing assertions like this: [block:code] { "codes": [ { "code": "[Test]\npublic void then_it_credits_the_account()\n{\n Assert.Equals(15.63, _accountBalance);\n}", "language": "csharp" } ] } [/block] The library provides extension methods that make assertions read more like English and thus are more friendly for humans: [block:code] { "codes": [ { "code": "[Test]\npublic void then_it_credits_the_account()\n{\n _accountBalance.ShouldEqual(15.63);\n}", "language": "csharp" } ] } [/block] Below are some examples of extension methods provided by the Should library. [block:code] { "codes": [ { "code": "_account.ShouldBeNull();\n_account.ShouldNotBeNull();\n_account.ShouldBeType<Account>();\n_account.ShouldNotBeType<Vehicle>();\n\n_purchaseConfirmation.ShouldEqual(\"Your purchase completed successfully\");\n_purchaseConfirmation.ShouldNotEqual(\"Your credit card was declined\");\n\n// Booleans\n_transactionCompleted.ShouldBeTrue();\n_transactionCompleted.ShouldBeFalse();\n\n// Strings\n\"This could be a really long string\".ShouldContain(\"really long string\");\n\"This could be a really long string\".ShouldNotContain(\"something that shouldn't be here\");\n\"This string contains text\".ShouldNotBeEmpty();\n\n// Lists\n_tags.ShouldContain(\"Green\", \"Blue\");\n_tags.ShouldNotContain(\"Yellow\");\n_tags.ShouldBeEmpty();", "language": "csharp" } ] } [/block]