[EDIT] Based on feedback yes, VS2010 seems to support SL4 Library TDD despite a couple strange messages when first creating the tests which said the test could not target Silverlight - problem seemed to go away - chalk it up to an RC bug I guess. I think my real out-standing question now is how to TDD a standalone library that uses elevated OOB functionality. The UI piece is not really needed for the Library development and gets in the way of what I actually want to TDD. I know I can (and will) mock some of that functionality but at some point I will also need the real thing in my tests.Thoughts?
[Original Question] First I am glad to see better TDD support in VS2010. Support for generating code stubs from my tests is ok - not as good as more mature TDD plug-ins but a good start.
I am looking for some best Silverlight 4.0 TDD practices. First Question: Anyone have links, recommendations? I know the new Silverlight Unit Test capabilities are much better (Jeff Wilcox's Mix Presentation). What I am focusing on right now is using TDD to develop pure Silverlight 4.0 Class Library projects - projects without a Silverlight UI project. I've been able to get it to work but not as cleanly as it should be.
I can create an Empty VS project.
Add A Silverlight 4 Class Library Project.
Add a TestProject (not a silverlight Unit Test Project but a plain Test Project).
Add a simple test in the Test Project such as:
namespace Calculator.Test
{
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void CalulatorAddTest() {
Calc c = new Calc();
int expected = 10;
int actual = c.Add(6, 4);
Assert.AreEqual<int>(expected, actual);
}
}
}
Using the new Generate Type and Method from Test feature it will generate the following code in the Silverlight Project:
namespace Calculator
{
public class Calc
{
public int Add(int p, int p_2) {
throw new NotImplementedException();
}
}
}
When I run the tests the first time it says the target assembly is Silverlight and not able to run test - Not exact text but the same general idea.
When I change the implementation to:
namespace Calculator
{
public class Calc
{
public int Add(int p, int p_2) {
return p + p_2;
}
}
}
and re-run the test, it works fine and the test goes green. It also works for all other TDD code I generate after. I also get a warning Mark in the Test Project's reference to the Calculator Silverlight Class Library Assembly.
Second Question: Any comments ideas if this just a bug in VS2010 RC or is Silverlight Class Library TDD not really supported. I have not created a Silverlight UI project or changed and build or debug settings so I have no idea what is hosting the silverlight DLL.
Finally, some of the Silverlight Clas开发者_开发问答s Libraries I need to write will provide functionality that requires elevated Out-Of-Browser rights. Based on the above, it looks like I can use TDD Test Projects against regular Silverlight 4.0 Class Libraries, but I have no idea how I can TDD the elevated OOB functionality without also creating the UI component that gets installed. The UI piece is not really needed for the Library development and gets in the way of what I actually want to TDD. I know I can (and will) mock some of that functionality but at some point I will also need the real thing in my tests. Third Question: Any ideas how to TDD Silverlight 4.0 Class Library project that requires OOB elevated rights?
Thanks!
TDD is for sure supported for SL4, what i suggest is to look at source code of MEF or CAL for SL4
精彩评论