Currently we have a few unit tests, although this is sure to increase, which test code should work in any locale ( culture in .NET terms ). To test this we currently have an implementation such as
public AppVersionTest()
{
// Set the current locale to French Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Assert.AreEqual(3.6, Tranmit.Sprinter.Configuration.Database.TBConfig.ApplicationVersion, "Failed to read the configuration ApplicationVersion");
}
We did this as we actually had a bug when the code was running on a french machine. I thought a better pattern would actually tests the code in all defined cultures e.g. changing the implementation to
// Obtain the current culture
CultureInfo oldCurrentCulture = Thread.CurrentThread.CurrentCulture;
try
{
foreach(CultureInfo cInfo in CultureInfo.GetCultures(CultureTypes.AllCultures)
{
Thread.CurrentThread.CurrentCulture = cInfo
// Perform test code
}
}
finally
{
// Restore the previous culture
Thread.CurrentThread.CurrentCulture = oldCurrentCulture;
}
Any code which is locale independant should certainly work in any culture e.g. if monetary code was being tested the culture would allow the code to find thousand / decimal separators values, so this seems a sensible implementation. However this certainly strikes me as a pattern which NUnit could implement for test methods decorated with an attribute such as TestAllCultures which would reduce this to
Test, TestAllCultures]
public AppVersionTest()
{
// Test code
}
This would certainly reduce a lot of boilerplate code required for each test method and I'm sure useful to many other developers who have to write code which works across all cultures.
Wednesday, September 20, 2006
Subscribe to:
Post Comments (Atom)
3 comments:
Very nice! I like it. steve jobs pixar disney
Hi man! Thanks for the site!
louis vuitton replica sun glasses
cash advance payday paycheck
loan online payday quick
loan online personal quick
payday cash advance no fax required
cash advance and payroll loan
100 advance cash online payday
advance lender loan payday
cash emergency fast loan loan loan payday quick
home equity loan calculation
free credit report and beacon score
See you soon!
hello
thanks for this information
Post a Comment