YUI测试是一款基于浏览器,提供解决方案的测试框架。使用YUI,您可以方便地添加单元测试,寻求">JavaScript解决方案。它是由Yahoo! UI Library开发的一个JavaScriptMVC测试插件,能够让你模范大部分DOM动作,比如写,拖拽,比如模范AJAX响应,并且能够使用断言 (assertions)。它能够象函数一样运行,并且能够在不同的console窗口进行集成测试。虽然它不是在任何 xUnit 框架基础上开发而来,但YUI Test仍然有很多nUnit 和 JUnit的所具有的特性。( While not a direct port from any specific xUnit framework, YUI Test does derive some characteristics from nUnit and JUnit. 这段翻译得不好,但相信大致意思是对的)。
Late last year we released the beta 1 version of YUI Test. Since that time, we’ve been gathering feedback, fixing bugs, and implementing new features. Today I’m happy to announce the availability of YUI Test 1.0.0 beta 2, the last planned beta release before GA. This release features some new core functionality as well as initial support for Node.js. All of this is designed to make YUI Test a more complete testing solution no matter where you write JavaScript.
Core Changes
Based on feedback from the YUI community, there have been some important additions to the YUI Test core. The first such change is the introduction of init() and destroy() on TestCase objects. Prior to this release, you could use setUp() and tearDown() to initialize and cleanup data needed to run tests. In the traditional xUnit style, setUp() ran before every test and tearDown() ran after every test. The init() and destroy() methods each run only once per TestCase object: init() runs first, before the first call to setUp(), and destroy() runs last, after the last call to tearDown(). These methods are useful for setting up data that the entire TestCase needs. For example:
var testCase = new YUITest.TestCase({
name: "TestCase Name",
//---------------------------------------------
// init and destroy
//---------------------------------------------
init : function () {
this.data = { name : "Nicholas", age : 28 };
},
destroy : function () {
delete this.data;
},
//---------------------------------------------
// Tests
//---------------------------------------------
testName: function () {
YUITest.Assert.areEqual("Nicholas", this.data.name, "Name should be 'Nicholas'");
},
testAge: function () {
YUITest.Assert.areEqual(28, this.data.age, "Age should be 28");
}
});