I’m trying to get a Silverlight 4 unit test to work (using the framework from Microsoft that’s installed with the Silverlight Toolkit) and get a NullReferenceException checking the Text property of a TextBlock. I’m sure I’m missing something in getting the xaml page to load / initialise. Here’s the code:
[TestClass]
public class Tests
{
private MainPage _myPage;
[TestInitialize]
public void PreparePage()
{
_myPage = new MainPage();
}
[TestMethod]
public void TitleIsInInitialState()
{
Assert.AreEqual(_myPage.myTextBlock.Text, "myText");
}
}
I then run the html page that refers to my Silverlight unit test project. What am I missing?
Thanks,
Krip
Is the
MainPage()constructor throwing an exception?I’ve found that the Silverlight test runner rather helpfully swallows exceptions thrown in methods with the
[TestInitialize]attribute. Try moving the line_myPage = new MainPage();to your test method.