自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用Titanium做單元測(cè)試

移動(dòng)開發(fā)
官方文檔中什么也沒有提到,單元測(cè)試中可以使用喜歡的Javascript測(cè)試框架。因?yàn)椴灰蕾嚍g覽器,所以只要能確認(rèn)Log輸出的即可。

總之,為了在Titanium的控制臺(tái)輸出Log,Titanium.API.info和Titanium.API.error等能測(cè)試輸出就可以了。

這回我們?cè)囍褂肬nit系中流行的QUnit和BDD系的Jasmine。

使用QUnit

Titanium使用的Adapter已經(jīng)在GitHub上公開了。

lukaso/qunit–GitHub

在自己的Project使用的時(shí)候,Resources文件夾下保存一下文件就可以了。

*runner.js

*qunit/qunit.js

*qunit/titanium_adaptor.js

*test/tests_to_run.js

然后,在test/tests_to_run.js中寫測(cè)試內(nèi)容。在app.js的任何位置把runner.js文件include后運(yùn)行即可。

查看titanium_adaptor.js的內(nèi)容,我們可以看到,它做的事情就是利用QUnit的Logging處理把Log輸出到Titanium的控制臺(tái)上。

所以想輸出的時(shí)候,按照喜歡的改寫也是不難的事情。

在app.js中添加代碼確認(rèn)動(dòng)作

app.js_snippet中,Tabgroup中追加單元測(cè)試用的Tab,只是簡(jiǎn)單的確認(rèn),單純的在app.js的末尾追加一下行即可測(cè)試動(dòng)作:

Js代碼

  1. Titanium.include('runner.js'); 

確認(rèn)動(dòng)作的test/tests_to_run.js

為了確認(rèn)動(dòng)作,什么測(cè)試也沒有寫,只是測(cè)試QUnit的動(dòng)作的例子代碼:

  1. module("QUnitonTitanium"); 
  2.  
  3. test("OKtest(pass)",function(){ 
  4.  
  5. ok(true); 
  6.  
  7.  
  8. ); 
  9.  
  10. test("equaltest(nopass)",function(){ 
  11.  
  12. equal('hogehoge','hige'); 
  13.  
  14.  
  15. ); 

動(dòng)作結(jié)果會(huì)很好的輸出到Titanium的控制臺(tái)上。

順便說一下,由于結(jié)果中包含了HTML代碼,很難理解。使用QUnit-TAP不是很好。

使用Jasmine

Jasmine中,能夠自定義測(cè)試出力的Reporter,所以可以做成Titanium用的Reporter。

jasmine.js中,提供了基本的Reporter類,可以根據(jù)它做成自己的Reporter類。

實(shí)際編碼的時(shí)候可以參考Jasmine官方發(fā)布版本中的jasmin-html.js和jasmine.console_reporter.js。

包含了很好出力的Reporter的JasmineTitanium也已經(jīng)公開了。

在app.js中添加代碼確認(rèn)動(dòng)作

還沒有任何測(cè)試內(nèi)容,只是確認(rèn)Jasmine動(dòng)作的例子代碼。

前提是在Resorses/jasmine中,jasmine.js和jasmine-titanium.js(上邊的TitaniumReporter)

Js代碼

  1. Ti.include('jasmine/jasmine.js'); 
  2.  
  3. Ti.include('jasmine/jasmine-titanium.js'); 
  4.  
  5. describe("JasmineSample",function(){ 
  6.  
  7. it("pass!",function(){ 
  8.  
  9. varfoo=2; 
  10.  
  11. expect(foo).toEqual(2); 
  12.  
  13.  
  14. ); 
  15.  
  16. }); 
  17.  
  18. describe("SecondJasmineSample",function(){ 
  19.  
  20. it("fail!",function(){ 
  21.  
  22. varfoo=1; 
  23.  
  24. expect(foo).toEqual(2); 
  25.  
  26.  
  27. ); 
  28.  
  29. }); 
  30.  
  31. jasmine.getEnv().addReporter(newjasmine.TitaniumReporter()); 
  32.  
  33. jasmine.getEnv().execute(); 

執(zhí)行結(jié)束后,就能看到失敗的測(cè)試和合計(jì)結(jié)果。

實(shí)際的開發(fā)中,應(yīng)該把測(cè)試代碼統(tǒng)一放在spec文件夾中比較好。

注:

沒有spec文件夾或者文件夾為空是不能啟動(dòng)的。

責(zé)任編輯:佚名 來(lái)源: tidevcn
相關(guān)推薦

2017-01-14 23:26:17

單元測(cè)試JUnit測(cè)試

2017-01-16 12:12:29

單元測(cè)試JUnit

2017-01-14 23:42:49

單元測(cè)試框架軟件測(cè)試

2017-03-23 16:02:10

Mock技術(shù)單元測(cè)試

2023-07-26 08:58:45

Golang單元測(cè)試

2013-06-04 09:49:04

Spring單元測(cè)試軟件測(cè)試

2019-12-18 10:25:12

機(jī)器學(xué)習(xí)單元測(cè)試神經(jīng)網(wǎng)絡(luò)

2021-09-18 15:40:03

Vue單元測(cè)試命令

2024-10-16 16:09:32

2021-03-28 23:03:50

Python程序員編碼

2010-03-04 15:40:14

Python單元測(cè)試

2020-08-18 08:10:02

單元測(cè)試Java

2022-05-09 08:55:52

ORMMockGo

2019-01-29 09:00:44

PyHamcrest單元測(cè)試框架

2023-08-02 13:59:00

GoogleTestCTest單元測(cè)試

2021-05-05 11:38:40

TestNGPowerMock單元測(cè)試

2011-07-04 18:16:42

單元測(cè)試

2020-05-07 17:30:49

開發(fā)iOS技術(shù)

2011-08-11 13:02:43

Struts2Junit

2011-05-16 16:52:09

單元測(cè)試徹底測(cè)試
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)