標籤:des style http java os io 檔案 ar
首先建立環境情境:
一般三個目錄
lib jasmine的系統檔案存放目錄
spec 寫測試案例的目錄
src 存放原始碼的目錄(被測對象)
specRunner.html 測試入口檔案。
入口檔案內容:
--------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-core/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-core/jasmine.css">
<script type="text/javascript" src="lib/jasmine-core/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-core/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-core/boot.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="js_file_要測試的原始碼.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/Spec測試案例檔案.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>
--------------------------
在 spec 目錄中,寫個測試案例。寫如下內容:
-------------------------
describe("This is an exmaple suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
expect(false).toBe(false);
expect(false).not.toBe(true);
});
});
-------------------------
測試三個用例樣本。
1,true == true 為通過
2,false == false 為通過
3,false != true 為通過
此時這個用例通過。
參考:
https://github.com/pivotal/jasmine