学习jsunit一个Demo

 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 2 <html>
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 5     <script type="text/javascript" src="../app/jsUnitCore.js"></script>
 6     <script type="text/javascript">
 7 /*
 8         断言的语法
 9         assert([comment], booleanValue)
10       assertTrue([comment], booleanValue)
11       assertFalse([comment], booleanValue)
12       assertEquals([comment], value1, value2)
13       assertNotEquals([comment], value1, value2)
14       assertNull([comment], value)
15       assertNotNull([comment], value)
16       assertUndefined([comment], value)
17       assertNotUndefined([comment], value)
18       assertNaN([comment], value)
19       assertNotNaN([comment], value)
20       fail(comment)
21 */  
22         /*页面只执行一次*/
23         function setUpPage(){
24             //初始化测试变量
25         }
26 
27         var a = 4;
28         var b = 5;
29 
30         /*每个测试都会执行一次*/
31         function setUp(){
32             a++;
33         } 
34 
35         /*生产代码
36         function add(){
37             return a+b;
38         }
39 
40         /*测试方法*/
41         function testAlert(){
42             assertEquals('equals',10,add());
43         }   
44         /*测试结束后的代码*/
45         function tearDown(){
46             a = null;
47             b = null;
48         }
49         function testHello(){
50             assertEquals('equals',10,add());
51         } 
52 
53         /*手动加载待测试方法*/
54         function exposeTestFunctionNames() {
55           var tests = new Array(2);
56           tests[0] = "testValidArgs";
57           tests[1] = "testWithNegativeNumbers";
58           return tests;
59       }
60     </script>
61 </head>
62 <body>
63 </body>
64 </html>

 

posted @ 2013-01-07 17:49  linksgo2011  阅读(170)  评论(0编辑  收藏  举报