common test 記錄

來源:互聯網
上載者:User

erlang 字串串連要用string:concat/2或string:join/2,不能用++

以GUI方式啟動common test

ct_run -vts -browser firefox -config cfg/test.cfg -logdir logs/ -dir ./ -erl_args -pa /home/louieli/work/test/itf -s inets start

命令列方式啟動ct

首先修改erlang開機檔案start.boot,配置inets為預設啟動

louieli@ubuntu:~$ cp /usr/local/lib/erlang/releases/R14B03/start.script my.script

louieli@ubuntu:~$ vim my.script

    {apply,{application,start_boot,[kernel,permanent]}},

    {apply,{application,start_boot,[stdlib,permanent]}},

     {apply,{application,start_boot,[inets,permanent]}},

louieli@ubuntu:~$ erl

Erlang R14B03(erts-5.8.4) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe][kernel-poll:false]

 

Eshell V5.8.4  (abort with ^G)

1>systools:script2boot("my").

ok

 

louieli@ubuntu:/usr/local/lib/erlang/bin$sudo mv start.boot start.boot.bak

louieli@ubuntu:/usr/local/lib/erlang/bin$sudo mv ~/my.boot start.boot

 

在home目錄建.erlang檔案,加入搜尋路徑

root@bt:~/dbank/test/testProduct# cat .erlang

code:add_patha("/root/dbank/test/testProduct").

code:add_patha("/root/dbank/test/itf").

ct_run -config /home/louieli/work/test/testNSP/cfg/test.cfg -logdir /home/louieli/work/test/logs/  -dir /home/louieli/work/test/testNSP -erl_args -pa /home/louieli/work/test/itf

#指定testsuite

root@bt:~/dbank/test/testProduct#ct_run -config /root/dbank/test/testProduct/cfg/production.cfg -logdir /root/dbank/test/logs/ -suite app_weibo_SUITE -erl_args -pa /root/dbank/test/itf

通過{save_config,ConfigList}和{Saver,ConfigList} =?config(saved_config,Config)只能在相鄰的兩個用例之間傳遞資料。

用例是按照在all/0中出現的先後順序執行的

<suite_name>_SUITE.erl

end_per_testcase/2 可以通過從Config 檢測 tc_status得到testcase是否通過,tc_status可以為ok,{failed,Reason},{skipped,Reason}

當testcase 因為 timetrap timeout 或 ct:abort_current_testcase/1 終止時,end_per_testcase仍會執行,只不過是在另外的進程裡,不能改變testcase終止的原因和配置。其它情況 init_per_testcase 和 end_per_testcase 和 test case是在同一個進程中執行,此時,end_per_testcase 可以通過返回{fail,Reason}改變testcase失敗的原因。

testcase 中的參數 config 與啟動時的 config檔案是不一樣的。config檔案配置了SUT的一些必要資訊,參數config是當前test suit 和 test case 執行時的動態配置資訊

ct:userdata/3

suit() 和 testcase/1 返回的[Info]資料可以用ct:userdata獲得,config參數中的資訊可以用?Config宏取得

privDir = ?Config(priv_dir,Config)

testcase1() ->

  [{require,ftp},

   {default_config,ftp,[{ftp,"my_ftp_host"},

                                      {username,"aladdin"},

                                      {password,"sesame"}]}]

可以用default_config 指定預設的配置

測試組之間的屬性是獨立的,不存在繼承關係

?Config(tc_group_result,Config)

用 -dir 指定測試目錄時,CT會先在指定的目錄中檢查是否有tes子目錄,如果test子目錄存在,就用test子目錄作為測試目錄,否則用指定的目錄做為測試目錄

如果init_per_suit 中 新加的config 項與 init_per_testcase中新加的config項重名的話,config中會同時存在這兩個項,在testcase中用?Config取時會取到init_per_testcase中新加項的值

用例之間不要依賴

公用的部分做成單獨的模組

可以用Save_Config 來在用例和test suite之間傳遞資料

{Save_Config,ConfigList} 

{Saver,ConfigList} = ?Config(Saved_Config,Config)

{Skip_and_Save,Reason,ConfigList}

可以通過建立 testgroup 並指定 [sequence] 來 顯示指定用例的順序

Test cases in a sequence will be executed in order until they have all succeeded or until one case fails.

config file 只能通過 ct:get_config 讀取,testcase中的參數Config 可以通過 ?Config讀,這些資訊要先在testcase中讀出來才能傳遞

testcase的Config是獨立的,若要傳遞資料可以用 {Save_Config,ConfigList}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.