Hooked on LINQ

Hooked on LINQ - Developers' Wiki
for .NET Language Integrated Query

Quick Search


Rethinking Unit Testing Codecamp Seattle Notes

Modified: 2008/01/27 02:28 by t_magennis - Categorized as: CodeCamp
Edit

Rethinking Unit Testing: xUnit.Net



- Brad Wilson, Jim Newkirk

- Get it at: xUnit Core, Extensions


- The T in TDD is wrong: Replace [Test] with [Fact] and [Theory]


- Be Flexible: Removed [TestFixture]; Added static test methods, Added private test methods. TestFixture was an optomization and not essential.


- Be Safe: Create a new instance for each test method. Tests are run in a random order - on purpose!


- Be Sure: Removed [ExpectedException]. Exactly the right code is tested, and expected exception can hide code later in a test method.


- Be Extensible: Override how built-in exceptions work, Add pre and post operations for a test method.


- Extension methods are being explored. I.e. x.ShouldEqual(4); x.ShouldBeNull();


- Once you understand that a new object is created for every test method, the constructor becomes the setup, and the IDisposible Dispose method becomes the teardown. Method specific cleanup within the test method.


- Clock class shipped as part of the extensions to wrap the DateTime.Now. You can set it and also "freeze" time for comparing using the [Fact, FreezeClock]. - need to play to determine what this is use for!


- Assert.InRange(5, 1, 10); - would allow the actual to be between 1 and 10.


- Exception ex = Record.Exception( () => code ); returns null of no exception thrown, otherwise the exception that is thrown.


- Before and after methods taking MethodInfo allow you to do stuff before and after a fact.


- Fact is supposibly a statement that is always true; Theory is a statement that is true under certain conditions. Theory allow data driven tests.


[Theory]
[InLineData(42)]
[InLineData(-21)]
public void OurTheory(int x)
{
   Assert.True(x > 0);
}



Data can be inserted by InLineData, SQL, OLEDB, ExcelData (XLS file with named values not XLSX), and PropertyData (you define a Get property returning IEnumerable and specify its name).


- [RunWithNUnit] will run tests that are not xUnit in the NUnit runner. Allows you to migrate across without changing behavior.


- [Fact(Skip="This is a skipped test")] - same as [Ignore] test.


- [Fact(Timeout=100)] - Timeout and fails if test takes too long.


- Console options allow you to pass specific XSLT's and get console results in any format you need. Defaults ship for NUnit style, and a rich HTML report style.


- ASP.Net MVC goal (one) was Testing! (Wanting is a potential candidate for doing UI tests in ASP.Net)


- WPF has an automation UI; This allows acceptance testing.


- Silenium or Wantin are good candidates for ASP.Net.


If you would like to comment on this page, click on the Discuss button located on the top-right of each page. Feel free to edit any mistakes or ommissions you find. If you have an objection or find in-appropriate content then contact the administrator. This website is not affiliated with Microsoft®, all content and opinions are those of the specific author and some advice, solutions and article may contain un-intentional errors - please use care. Powered by ScrewTurn Wiki version 2.0.15. Some of the icons created by FamFamFam.