By default, vs2010 does not allow you to create a "Silverlight unit test" project, not vs2010, But Ms does not launch a template. It doesn't matter. Download one from the online template, for example:
After the installation is complete, you can create a sl unit test project, as shown in figure
One test:
First, create an SL class library project named sltools, which contains several lines of tests.Code:
Namespace sltools {public static class mathhelper {public static int add (int A, int B) {return a + B ;}}}
Create a sl unit test project named slunittest and create a test class. The Code is as follows:
Using system; using Microsoft. visual Studio. testtools. unittesting; using sltools; namespace slunittest {[testclass] public class mathhelperunittest {[testmethod] public void testaddmethod () {random RND = new random (); For (INT I = 0; I <10; I ++) {int A = RND. next (); int B = RND. next (); assert. areequal (mathhelper. add (A, B), (a + B ));}}}}
F5, run it: Note: unit testing is actually very useful for front-end web technologies such as SL. For example, the most commonly used WCF asynchronous calls cannot perform unit tests. for meaningful tests, they must be "automated tests based on the final UI page". Currently, such products are generally implemented by third parties, next Lecture.