完成以下步骤后再推进
按向下的箭头查看其他步骤
- 两个文件: 测试文件 + 参考文件
- 测试文件使用了你要测试的功能
- 参考文件没有使用待测功能,但在视觉匹配上是一样的
- 自描述(手工和自动测试都适用)
- 跨浏览器并且跨平台
CSS3 Transforms规范中transform属性的一个基本测试:使用translate()
函数
规范链接:
http://www.w3.org/TR/css3-transforms/#transform-property
http://www.w3.org/TR/css3-transforms/#two-d-transform-functions
按向下的箭头查看Windows的操作指令
更新你本地的CSSWG测试库
请完成该步骤,除非你刚把测试库复制下来
在终端中键入如下命令:
$ cd [path to repo]/test
$ hg pull -u
$ ls -lR contributors/ttwf/samples
注: 这些文件也可以从这里获取到:
ttwf-reftest-tutorial-starter.zip
按向上的键头查看OS X的操作指令
更新你本地的CSSWG测试库
请完成该步骤,除非你刚把测试库复制下来
在终端中键入如下命令:
> cd [path to repo]\test
> hg pull -u
> dir contributors\ttwf\samples
注: 这些文件也可以从这里获取到:
ttwf-reftest-tutorial-starter.zip
按向下的箭头查看Windows的操作指令
为你的新测试创建一个目录
$ cd [path to repo]/test/contributors/ttwf/
$ mkdir -p yourName/incoming
$ cd yourName/incoming
按向上的箭头查看OS X的操作指令
为你的新测试创建一个目录
> cd [path to repo]\test\contributors\ttwf
> mkdir yourName\incoming
> cd yourName\incoming
按向下的箭头查看Windows的操作指令
将起始文件拷贝到你的incoming目录
在之前创建的incoming目录中
$ cp -R ../../samples/ttwf-reftest-tutorial-starter/* .
按向上的箭头查看OS X的操作指令
将起始文件拷贝到你的incoming目录
在之前创建的incoming目录中
> xcopy /e ..\..\samples\ttwf-reftest-tutorial-starter .
在文本编辑器中打开ttwf-reftest-tutorial-starter-001.html
添加测试元数据
Title和Author
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms Test: transform property with translate function</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
. . .
注: 在CSSWG Wiki上有关于元数据的详细信息
http://wiki.csswg.org/test/format#template-details
添加测试元数据
参考文件的路径
<!DOCTYPE html>
<html>
<head>
. . .
<link rel="match" href="reference/ttwf-reftest-tutorial-starter-ref.html">
. . .
注: 在CSSWG Wiki上有关于元数据的详细信息
http://wiki.csswg.org/test/format#template-details
添加测试元数据
规范链接
<!DOCTYPE html>
<html>
<head>
. . .
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
. . .
注: 在CSSWG Wiki上有关于元数据的详细信息
http://wiki.csswg.org/test/format#template-details
给测试元素添加transform属性
<style type="text/css">
.greenSquare {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
transform: translate(100px,100px);
}
. . .
</style>
创建一个只在失败时可见的元素
<style type="text/css">
. . .
.redSquare {
position: absolute;
width: 98px;
height: 98px;
top: 101;
left: 101;
}
</style>
添加绿色填充颜色以显示通过状态
.greenSquare {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
transform: translate(100px,100px);
background: green;
}
添加红色填充颜色以显示失败状态
.redSquare {
position: absolute;
width: 98px;
height: 98px;
top: 101;
left: 101;
background: red;
}
</style>
在测试页上添加一句话使它变成自描述的测试
<body>
<p>The test passes if there is a green square and no red.</p>
. . .
</body>
在文本编辑器中打开reference/ttwf-reftest-tutorial-starter-ref.html
添加参考文件的元数据
Title和Author
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms Reference file</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
. . .
将参考元素的位置和颜色信息完全匹配测试文件的通过状态
<style type="text/css">
.greenSquare {
position: absolute;
width: 100px;
height: 100px;
top: 100;
left: 100;
background: green;
}
</style>
并添加自描述的句子
<body>
<p>The test passes if there is a green square and no red.</p>
. . .
</body>
在浏览器中检查你的测试和参考文件,确认它们是相同的
按向下的箭头查看本例的带提供商前缀的版本
.greenSquare {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
-webkit-transform: translate(100px,100px);
-moz-transform: translate(100px,100px);
-ms-transform: translate(100px,100px);
-o-transform: translate(100px,100px);
background: green;
}
按向下的箭头查看手工添加提供商前缀的另一个方法
在测试开发时我们推荐使用的脚本:
http://leaverou.github.com/prefixfree
prefixfree.jsapi.js扩展可用于无前缀的JS API测试:
https://github.com/LeaVerou/prefixfree/tree/gh-pages/plugins
在测试开发中,像这样引用这些脚本:
<-- 记得在提交给W3C前移除 -->
<script src="prefixfree.js"></script>
<script src="plugins/prefixfree.jsapi.js"></script>
按向下的箭头查看Windows的操作指令
将你的测试和参考文件添加到代码库中
$ cd [path to repo]/test/contributors/ttwf/yourName/incoming
$ hg add ttwf-reftest-tutorial-001.html
$ hg add reference
$ hg commit -m "TTWF reftest tutorial"
$ hg push
注: 如果你收到如下错误信息:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository
按如下的步骤来解决问题:
只在你收到上述错误时进行以下步骤
$ hg pull
$ hg merge
$ hg commit -m "Merge"
$ hg push
按向上的箭头查看OS X的操作指令
将你的测试和参考文件添加到代码库中
> cd [path to repo]\test\contributors\ttwf\yourName\incoming
> hg add ttwf-reftest-tutorial-001.html
> hg add reference
> hg commit -m "TTWF reftest tutorial"
> hg push
注: 如果你收到如下错误信息:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository
按如下的步骤来解决问题:
只在你收到上述错误时进行以下步骤
> hg pull
> hg merge
> hg commit -m "Merge"
> hg push
按向下的箭头查看Windows的操作指令
整合反馈意见并将测试移到submitted目录
$ cd [path to repo]/test/contributors/ttwf/yourName
$ hg pull -u
$ hg merge
$ hg commit -m "merging"
$ hg mv incoming/ttwf-reftest-tutorial-001.html submitted/ttwf-reftest-tutorial-001.html
$ hg mv incoming/reference/ttwf-reftest-tutorial-ref.html submitted/reference/ttwf-reftest-tutorial-ref.html
$ hg commit -m "moved the TTWF reftest tutorial to the submitted folder"
$ hg push
按向上的箭头查看OS X的操作指令
整合反馈意见并将测试移到submitted目录
> cd [path to repo]\test\contributors\ttwf\yourName
> hg pull -u
> hg merge
> hg commit -m "merging"
> hg mv incoming\ttwf-reftest-tutorial-001.html submitted\ttwf-reftest-tutorial-001.html
> hg mv incoming\reference\ttwf-reftest-tutorial-ref.html submitted\reference\ttwf-reftest-tutorial-ref.html
> hg commit -m "moved the TTWF reftest tutorial to the submitted folder"
> hg push
testharness.js和testharnessreport.js
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
按向下的箭头获取更多信息
id="log"
的元素
test(test_function, name, properties)
async_test()
是用于异步测试的test()
的调用test()
调用会显示PASS/FAIL信息按向下的箭头获取更多的信息
test(test_function, name, properties)
test_function
必须是一个对象,不是一个函数调用test_function
应该包含测试断言方法
test(function() { assert_true(true) }, name, properties)
test(test_function, name, properties)
name
是用于标识测试的字符串name
应该简短,唯一,并且不会改变name
会显示在测试结果表格里
test(function() { assert_true(true) }, "test_name", properties)
test(test_function, name, properties)
properties
使用覆盖默认值的对象properties
是可选参数timeout
和metadata
test(function() { assert_true(true) }, "test_name",
{timeout:1000,
help: 'http://www.w3.org/TR/spec#section',
author: ['Bill Gates <bgates@msn.com>', 'Steve Jobs http://apple.com/sjobs'],
assert: 'This should always be true.'})
关于定于测试元数据的细节, 可以查看CSSWG Script Test Wiki Page
test()
服务的test_function
中description
参数,只在断言失败的时候才输出
test()的调用中
按向下的箭头获取详细的信息
assert_equals(actual, expected, description)
actual
: 所测功能的实际值expected
: 期望值description
(可选): 仅在断言失败时输出
assert_equals(getActualData("myElement"), 100, "Expected value for myElement is 100")
CSS3 Transforms规范中transform属性的一个基本测试:使用translate()
函数
与参考测试的例子类似, 但这次测的是API而不是渲染
规范链接:
http://www.w3.org/TR/css3-transforms/#transform-property
http://www.w3.org/TR/css3-transforms/#two-d-transform-functions
按向下的按钮获取更多的信息
复制一份JavaScript起始文件
在文本剪辑器中打开ttwf-js-tutorial-001.html
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="assert" content="The transform should be translate(100px,100px)">
</head>
<body>
</body>
</html>
更新元数据
author
元数据flags
元数据
flags
描述了测试的先决条件flags
列表在CSSWG Wiki上可以查到Test Format
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Jim Tester" href="mailto:jimmyt@yahoo.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
导入W3C JavaScript测试框架文件
将如下代码添加到head
块里
...
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js">></script>
...
注: 在开发过程中, resources
目录的路径应该和该目录在本地的位置相匹配
在提交到CSSWG测试库前,脚本的路径必须指向/resources
目录
head
块应该显示如下
author
元数据应该包含你实际的名字和邮箱
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
...
添加一个div
到<body>
中以作为测试元素
...
<body>
<div id="myDiv"></div>
<body>
...
transform
将应用于该元素
添加一个id="log"
的<div>
用于显示测试结果
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<body>
...
testharness.js会添加包含测试结果的HTML表格到该元素
创建一个<script>
块来包含JavaScript代码
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
</script>
<body>
...
文件内容应该显示如下
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
</script>
</body>
</html>
用JavaScript设置测试元素的transform
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
// Set the transform
document.getElementById("myDiv").style.transform = "translate(100px,100px)";
</script>
</body>
</html>
在script
块中添加一个test()
的调用
在test_function
中使用assert_equals
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
// Set the transform
document.getElementById("myDiv").style.transform = "translate(100px,100px)";
// Verify that the transform was set as expected
test(function() {assert_equals( //test arg1: test_function
document.getElementById("myDiv").style.getPropertyCSSValue("transform").cssText, //assert_equals arg 1: actual
"translate(100px,100px)", //assert_equals arg 2: expected
"transform should be translate(100px,100px)")}, //assert_equals arg 3: description
"Transform_Translate_100px_100px"); //test arg2: name
</script>
</body>
</html>
参数的注释只用于澄清用途, 可以忽略
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
document.getElementById("myDiv").style.transform = "translate(100px,100px)";
test(function() {assert_equals(
document.getElementById("myDiv").style.getPropertyCSSValue("transform").cssText,
"translate(100px,100px)", "transform should be translate(100px,100px)")},
"Transform_Translate_100px_100px");
</script>
</body>
</html>
按向下的箭头获取Windows的操作指令
将你的测试文件添加到代码库
$ cd [path to repo]/test/contributors/ttwf/yourName/incoming
$ hg add ttwf-js-tutorial-001.html
$ hg commit -m "TTWF JavaScript tutorial"
$ hg push
如果你收到如下错误信息:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository. 这样解决:
$ hg pull
$ hg merge
$ hg commit -m "Merge"
$ hg push
按向上的箭头获取OS X的操作指令
将你的测试文件添加到代码库
> cd [path to repo]\test\contributors\ttwf\yourName\incoming
> hg add ttwf-js-tutorial-001.html
> hg commit -m "TTWF JavaScript tutorial"
> hg push
如果你收到如下错误信息:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository. 这样解决:
> hg pull
> hg merge
> hg commit -m "Merge"
> hg push
按向下的箭头获取Windows的操作指令
整合反馈意见并将测试移到submitted目录
$ cd [path to repo]/test/contributors/ttwf/yourName
$ hg mv incoming/ttwf-js-tutorial-001.html submitted/ttwf-js-tutorial-001.html
$ hg commit -m "moved the TTWF JavaScript tutorial to the submitted folder"
$ hg push
按向上的箭头获取OS X的操作指令
整合反馈意见并将测试移到submitted目录
> cd [path to repo]\test\contributors\ttwf\yourName
> hg mv incoming\ttwf-js-tutorial-001.html submitted\ttwf-js-tutorial-001.html
> hg commit -m "moved the TTWF JavaScript tutorial to the submitted folder"
> hg push
你已经完成了W3C参考测试和JavaScript测试
按向下的箭头获取更多信息
按向下的箭头获取更多信息
abort: push creates new remote head ...