//包含特性声明的函数要以";"结尾,不可省略
[TestMethod],[DebugOutput(true)]
UnitTest.prototype.testString = function() //测试字符串方法,这里假设自己实现了一个String类然后来测试
{
var testCase = new String();
testCase = "abc";
this.Test(testCase == "abc"); //测试赋值操作
testCase += "def";
this.Test(testCase == "abcdef"); //测试连接操作
this.Test(testCase.length == 6); //测试长度属性
self.output.value += "\n";
var result = "Debug - testString finished with " + this.passed + " cases passed and " + this.errors + " cases failed!\n";
this.passed = 0;
this.errors = 0;
return result;
};
//只测试不输出调试信息的方法
[TestMethod]
UnitTest.prototype.testRegexp = function()
{
var errors = 0;
var passed = 0;
if(/abc/.test("abc"))
{
self.output.value += ".";
passed ++;
}
else
{
self.output.value += "e";
errors ++;
}
if(/abc/.test("aababcd"))
{
self.output.value += ".";
passed ++;
}
};
//不被测试的方法
UnitTest.prototype.foo = function()
{
alert(’foo not being tested!’);
};
UnitTest.prototype.runCases = function()
{
for (each in this)