在Titanium中使用tishadow进行单元测试( unit tests using tishadow)

访问量: 978

注意: 本文与:   http://siwei.me/blog/posts/titanium-add-unit-tests-for-titanium 有所重复. 建议看它. 

refer to:  http://www.yydigital.com/blog/2013/2/14/Testing_Alloy_With_Jasmine_And_TiShadow

1. 安装tishadow. (略)

2. 在titanium  目录下新建一个spec目录:

$ mkdir spec

3. 新建一个文件: spec/index_spec.js  

describe('should test index', function(){
  var Allog = require('alloy');
  var $;
  beforeEach(function(){
    $ = Alloy.createController('index');
  })

  describe('should say hi', function(){
    it('should show some content', function(){
      //$.__views.l.text.should ==
      expect($.__views.l.text).toEqual('Click Image of Apple Logo');
    })
  })
})

4. 连接你的设备(跟你的电脑处于同一个局域网):

$ ti build --platform android --target device --shadow 

5. 运行:  (唯一的遗憾是,如果能及时更新就好了)

2015-02-23 更新: 记得使用  (同时记得运行的命令是: (看到末尾的 --update 了么? 这样的话速度就会特别快)

$ tishadow spec -t mocha-should --platform android --update 

$ alloy compile --config platform=ios && tishadow spec --plaform=ios --update

可以看到下面的内容:
[INFO] 
[INFO] Alloy compiled in 1.21631s
[INFO] 118 file(s) bundled.
[INFO] BUNDLE sent.  
# 如果没有连接设备的话,你的屏幕就死在这里了。

[INFO] Alloy compiled in 1.21038s
[INFO] 81 file(s) bundled.
[INFO] BUNDLE sent.
[INFO] [android, 4.1.2, 192.168.1.108] Connected
# 需要等。。。大约1分钟。。。
[INFO] [android, 4.1.2, 192.168.1.108] Unpacking new bundle: test_ti
[INFO] [android, 4.1.2, 192.168.1.108] Requiring: appdata-private://test_ti/spec//index_spec.js
[TEST] [android, 4.1.2, 192.168.1.108] Runner Started
[TEST] [android, 4.1.2, 192.168.1.108] 
[TEST] [android, 4.1.2, 192.168.1.108] A suite
[TEST] [android, 4.1.2, 192.168.1.108]     √ contains spec with an expectation
[PASS] [android, 4.1.2, 192.168.1.108] √ 1 test(s) completed.
[TEST] [android, 4.1.2, 192.168.1.108] 
[PASS] [android, 4.1.2, 192.168.1.108] √ 1 spec(s) completed.

订阅/RSS Feed

Subscribe

分类/category