1 / 36

xUnit Extensibility

xUnit.net Extensibility. Brad Wilson Jim Newkirk. Schedule. Assert Extensibility 9:00 Before/After Extensibility 9:45 Fact Extensibility 10:15 BREAK 10:45 Fixture Extensibility 11:00 Runner Extensibility 11:30 Putting it all Together 11:45. Assert Extensibility.

erica
Download Presentation

xUnit Extensibility

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. xUnit.net Extensibility Brad WilsonJim Newkirk

  2. Schedule Assert Extensibility 9:00 Before/After Extensibility 9:45 Fact Extensibility 10:15 BREAK 10:45 Fixture Extensibility 11:00 Runner Extensibility 11:30 Putting it all Together 11:45

  3. Assert Extensibility

  4. Not Easy to Add New Asserts • Limitations of the platform & language • Provide core assertions with the framework • Keep “assert language” consistent • No differentiation between failure and exceptions

  5. Customization of Comparisons • IEquatable / IEqualityComparer • Assert.Contains • Assert.Equal • IComparable / IComparer • Assert.InRange • Fallback for Contains & Equal

  6. Asserts that Return Values • When type is tested • Assert.IsAssignableFrom • Assert.IsType • Assert.Throws • When collections are tested • Assert.Single • Exception catcher • Record.Exception

  7. Example Compare dates without times

  8. Exercise Finish by 9:45

  9. Before/After Extensibility

  10. Design • Cross-cutting concerns • Reusable attribute • Initializing environment • Cleaning up after stateful tests • Runs regardless of test outcome • Has no access to test class or method • Unspecified order (compose for guarantee)

  11. Example Rollback database

  12. Brainstorming Exercise Finish by 10:15

  13. Fact Extensibility

  14. Design • Answers:“What is a test method?” • Enumeration of tests • Execution of tests • Metadata (skip, timeout, display name)

  15. Why? • Metadatachanges • “I want all my tests to have a timeout” • “I want the display name of my test to be something other than method name” • Enumeration changes • “I want this test method to be run many times, perhaps with different input values for each run” • Execution changes • “I want to do something different than just running the method with no parameters”

  16. Example [Theory] attribute

  17. Exercise Followed by break, back by 11:00

  18. Fixture Extensibility

  19. IUseFixture • Share reusable fixture setup and teardown • Constructor • Dispose • Most frameworks encourage base classes here • Lack of multiple inheritance in the CLR • “Inherit to be reused, not to reuse”

  20. Example Test data seed & cleanup

  21. ITestClassCommandand RunWith • Answers: “What is a test class?” • Pre- and post-fixture behavior • Pre- and post-test behavior • Test class creation & cleanup • Test method discovery • Test method ordering

  22. Example Remove Randomization

  23. Exercise Finish by 11:30

  24. Runner Extensibility

  25. Design • Version resilient runner APIs • Link against xunit.runner.utility.dll, not xunit.dll • Test assembly lives in a separate app domain • Assembly • Configuration File • (Optional) Shadow Copy

  26. Low-Level API • Exector (remote) • ExecutorWrapper(local) • On the wire, it’s: • XML as a string (for status) • Boolean continue flag (to cancel) • Don’t use this. 

  27. High-Performance API • Thin wrapper on top of ExecutorWrapper • TestRunner • TestRunnerResult • IRunnerLogger • Cracks the XML into simple values • Not stateful; callback is mandatory • Runners: MSBuild, TD.NET, Resharper

  28. Object-Oriented API • Object model on top of ExecutorWrapper • MultiAssemblyTestEnvironment • TestAssembly, TestClass, TestMethod • TestStatus • ITestMethodRunnerCallback • Cracks the XML into objects • Stateful; callback is optional • Runners: Console, GUI

  29. Project files (.xunit) • One or more assemblies • Output types & locations • Filters

  30. Example xunit.console

  31. Putting it all Together

  32. Example BDD with [Observation]

  33. Example BDD with SubSpec

  34. Example Amalga Best Practice Analyzer

  35. Exercise

  36. Thank You! http://xunit.codeplex.com/ @bradwilson @jamesnewkirk @xunit

More Related