Xunit: Perform all 'Assert'ions in one test method?
Posted
by Jörg Battermann
on Stack Overflow
See other posts from Stack Overflow
or by Jörg Battermann
Published on 2009-12-04T11:19:08Z
Indexed on
2010/05/09
15:28 UTC
Read the original article
Hit count: 438
Is it possible to tell xUnit.net to perform all e.g. Assert.True()
in one test method? Basically in some of our use/testcases all assertions belong logically to one and the same 'scope' of tests and I have e.g. something like this:
[Fact(DisplayName = "Tr-MissImpl")]
public void MissingImplementationTest()
{
// parse export.xml file
var exportXml = Libraries.Utilities.XML.GenericClassDeserializer.DeserializeXmlFile<Libraries.MedTrace.ExportXml>(
ExportXmlFile);
// compare parsed results with expected ones
Assert.True(exportXml.ContainsRequirementKeyWithError("PERS_154163", "E0032A"));
Assert.True(exportXml.ContainsRequirementKeyWithError("PERS_155763", "E0032A"));
Assert.True(exportXml.ContainsRequirementKeyWithError("PERS_155931", "E0032A"));
Assert.True(exportXml.ContainsRequirementKeyWithError("PERS_157145", "E0032A"));
Assert.True(exportXml.ContainsRequirementKeyWithError("s_sw_ers_req_A", "E0032A"));
Assert.True(exportXml.ContainsRequirementKeyWithError("s_sw_ers_req_C", "E0032A"));
Assert.True(exportXml.ContainsRequirementKeyWithError("s_sw_ers_req_D", "E0032A"));
}
Now if e.g. the first Assert.True(...)
fails, the other ones are not executed/checked. I'd rather not break these seven Assertions up into separate methods, since these really do belong together logically (the TC only is 'passed' entirely if all seven are passing all together).
© Stack Overflow or respective owner