Skip to content

Instantly share code, notes, and snippets.

@tucaz
Created December 8, 2010 12:36
Show Gist options
  • Save tucaz/733230 to your computer and use it in GitHub Desktop.
Save tucaz/733230 to your computer and use it in GitHub Desktop.
Generates one test method for each entry of external data using NUnit test framework
using NUnit.Framework;
namespace NUnitDataDriven
{
[TestFixture]
public class DataTests
{
[Test, TestCaseSource("GetDataForTesting")]
public void age_should_be_over_18(Data data)
{
Assert.IsTrue(
IsAgeOver18(data.Age)
);
}
private bool IsAgeOver18(int age)
{
return age > 18;
}
private Data[] GetDataForTesting()
{
return new Data[3] { new Data() { Age = 20 }, new Data() { Age = 22 }, new Data() { Age = 17 } };
}
}
public struct Data
{
public string Name { get; set; }
public int Age { get; set; }
}
}
@raphaelmolesim
Copy link

Vlw! Ajudou bastante!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment