javascript 的 jasmine 的測試語句

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.