Data-Driven Tests

To parameterize console tests, you can use the Data attribute to specify the set of values to use when executing the test. These values can be supplied as individual arguments, or as a single Array for the first argument, and will be passed into the test method as an argument. This is equivalent to setting Fact.Data: [Data( {value:"result",targetClass:StringFactory}, {value:7357,targetClass:NumberFactory} )] function FactoryStrategiesReturnCorrectTargets(data){ // Arrange var expected=data.value; var target=new data.targetClass(); // Act var actual=target.create(); // Assert Assert.Equal(expected, actual); }

If a data-driven test is also marked asynchronous, the first argument will be the callback method needed to complete the assertion, and the second argument will be the value supplied by the current data iteration: [Async,Data( {title:"title",url:""}, {title:"other title",url:""} )] function SetsPageTitle(callback,data){ // Arrange var expected=data.title; var target=data.url; // Act page.load(target, function(pageObject){ callback(function(){ var actual=pageObject.title; // Assert Assert.Equal(expected, actual); }); }) }