Created
January 7, 2016 13:01
-
-
Save miklund/5d94934a6b7b1b83c0fd to your computer and use it in GitHub Desktop.
2011-05-26 Data driven test cases in NUnit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Data driven test cases in NUnit | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2011/05/26/data-driven-test-cases-in-nunit.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private IEnumerable MassiveAmountOfUsers | |
{ | |
get { return GetMassiveAmountOfUsers(); } | |
} | |
private IEnumerable GetMassiveAmountOfUsers() | |
{ | |
var doc = XDocument.Load("users.xml"); | |
return | |
from user in doc.Descendants("user") | |
let username = user.Attribute("username").Value | |
let password = user.Attribute("password").Value | |
let expected = user.Attribute("success").Value | |
.Equals("true", StringComparison.InvariantCultureIgnoreCase) | |
select new object[] { username, password, expected }; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestCaseSource("MassiveAmountOfUsers")] | |
public void ShouldLogin(string username, string password, bool expected) | |
{ | |
/* Setup */ | |
var repository = new UserRepository(); | |
/* Test */ | |
var result = repository.Authenticate(username, password); | |
/* Assert */ | |
Assert.That(result, Is.EqualTo(expected)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<users> | |
<user username="fsse" password="dj7sihfs" success="true" /> | |
<user username="hgtd" password="sd122?=s" success="true" /> | |
<user username="asde" password="!!sf3mff" success="true" /> | |
<user username="bsfd" password="--sdfj+?" success="true" /> | |
<user username="aefb" password="!#¤%/(sd" success="true" /> | |
... | |
</users> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment