Presentation is loading. Please wait.

Presentation is loading. Please wait.

XUnit.net Extensibility Brad Wilson Jim Newkirk. Schedule Assert Extensibility9:00 Before/After Extensibility9:45 Fact Extensibility10:15 BREAK10:45 Fixture.

Similar presentations


Presentation on theme: "XUnit.net Extensibility Brad Wilson Jim Newkirk. Schedule Assert Extensibility9:00 Before/After Extensibility9:45 Fact Extensibility10:15 BREAK10:45 Fixture."— Presentation transcript:

1 xUnit.net Extensibility Brad Wilson Jim Newkirk

2 Schedule Assert Extensibility9:00 Before/After Extensibility9:45 Fact Extensibility10:15 BREAK10:45 Fixture Extensibility11:00 Runner Extensibility11:30 Putting it all Together11: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?  Metadata changes  “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 ITestClassCommand and 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


Download ppt "XUnit.net Extensibility Brad Wilson Jim Newkirk. Schedule Assert Extensibility9:00 Before/After Extensibility9:45 Fact Extensibility10:15 BREAK10:45 Fixture."

Similar presentations


Ads by Google