Benchmarks
These benchmarks compare the happy-path overhead of aweXpect.Xml (passing assertions, the dominant case in a healthy test suite) against the equivalent FluentAssertions calls.
- Suite:
HappyCaseBenchmarksdriven by BenchmarkDotNet. - Job:
MediumRunwith the in-process toolchain. - Runner:
ubuntu-latestGitHub Actions agent, refreshed on every push tomain. - FluentAssertions has expectations on
XElementandXDocument, but not on XML strings. Where it lacks an expectation, its benchmark does what a FluentAssertions user writes instead, e.g. parse the string into anXDocument. - Each tab shows the latest measured time and allocated memory; bars are scaled within the row so length corresponds to magnitude. Lower is better.
- XML string
- Element
- Element order
- Attribute
Verifies that an XML string is equivalent to the expected one, regardless of its formatting and the order of its attributes.
FluentAssertions parses both strings into an XDocument.
await That(_xmlSubject).IsEqualTo(_xmlExpectation).AsXml();
XDocument.Parse(_xmlSubject).Should().BeEquivalentTo(XDocument.Parse(_xmlExpectation));
Verifies that an XElement is equivalent to the expected XML, regardless of its formatting and the order of its attributes.
FluentAssertions parses the expected XML into an XElement.
await That(_xmlElement).MatchesExactly(_xmlExpectation);
_xmlElement.Should().BeEquivalentTo(XElement.Parse(_xmlExpectation));
Verifies that an XElement with 10 child elements is equivalent to the expected XML with the child elements in reverse order.
FluentAssertions has no XML equivalency that ignores the element order, so it only approximates the expectation by comparing the sku attributes of the child elements in any order.
await That(_order).MatchesExactly(_reversedOrder, o => o.IgnoringElementOrder());
_order.Elements("item").Select(item => item.Attribute("sku")!.Value).Should()
.BeEquivalentTo(XElement.Parse(_reversedOrder).Elements("item").Select(item => item.Attribute("sku")!.Value));
Verifies that an XElement has an attribute with the expected value.
await That(_xmlElement).HasAttribute("title", it => it.IsEqualTo("Let It Be"));
_xmlElement.Should().HaveAttributeWithValue("title", "Let It Be");