個人資料
歸檔
正文

test automation

(2023-11-01 19:38:55) 下一個

1.Robotframework

其它語言的關鍵字用空格區分,robot用兩個空格區分。例如下列代碼:

相當於: select_radio_button(Gender='M'),input_text(&FirstName,"David")

子函數稱為customized keyword例如launchBrower(appurl, appnrowser):

(402) Part1- Introduction to Robot Framework | Environment Setup | Selenium with Python - YouTube 

中文手冊:https://robotframework-userguide-cn.readthedocs.io/zh-cn/latest/CreatingTestData/TestDataSyntax.html

Ride IDE:https://www.softwaretestinghelp.com/getting-started-with-robot-framework-ride/ 

用串口庫:https://github.com/whosaysni/robotframework-seriallibrary 

course: https://zhuanlan.zhihu.com/p/158122663 https://github.com/robotframework/QuickStartGuide 

pip install robotframework  #it might be under .local so add path if needed
robot --version
pip install -U wxPython       #not sure do we need it
pip install robotframework-ride  #ride is IDE
python -m robotide.__init__ 看到是ride v2.0.8.1,File|new project創建robot_test, Editor|Setup,大窗口輸入First test case,Text edit裏輸入如下,保存,Run。

第一個例子hello.robot隻需2行,用robot hello.robot運行:
Testcase1
    log    Hello, World!

第二個是python語言例子:
import os
import sys
class RobotTest:
def first_keyword(self):
fp = open("/tmp/robot_fk", "a")
fp.write("this is the first keywordrn")
fp.close()

Robot的測試用例和配置使用HTML,TXT等格式文件進行編輯,html是比較常用的一種格式,通過html繪製的表格形式來編輯用例可閱讀性較高。

Robot通過識別html表格中的表頭來確定該表格的配置是做合使用,例如Settings用來配置資源庫,Test Cases用來編輯測試用例,Variables用來配置默認的變量等等。

每個robot工程開始工作時會通過Settings加載相關的資源,通常為TestLib,或者導入其他的配置文件等等,然後找到所有的Test Cases表格並順序執行每個case。每個測試用例的每個步驟通常都是有一個關鍵字來執行操作該步驟。Robot會去Settings中指定的library中尋找該關鍵字,如果找到則執行該關鍵字所對應的代碼,如果在Lib代碼中無法找到該關鍵字,則尋找html的表中表頭為Keywords的表格,如果也無法找到則會報錯。執行測試用例時每個步驟都執行完且沒有報錯,則認為該條用例為pass。

2.CMocka

https://blog.csdn.net/benkaoya/article/details/100933141 

https://www.samlewis.me/2016/09/embedded-unit-testing-with-cmocka/ 

#include "tmp101.h"

static const float TMP_BIT_RESOLUTION = 0.0625;

float tmp101_get_temperature(void) 
{   
    // Need to set the TMP101 pointer register to point to the temp register
    uint8_t pointer_address = 0;
    i2c_transmit_blocking(TMP101_ADDRESS, 0, &pointer_address, 1);

    // The TMP101 stores 12 bit samples that are retrieved in two byte blocks
    uint8_t data[2];
    i2c_read_blocking(TMP101_ADDRESS, 0, &data[0], 2);

    // the 1st byte is bits 12 to 4 of the sample and the 2nd byte is bits 4 to 0
    // see page 16 of the TMP_101 datasheet
    uint16_t temperature_bits = (data[0] << 4) | (data[1] >> 4);

    // The 12 bit sample is represented using 2s complement, for simplicity 
    // (and because there's no 12 bit int representation), scale up the sample
    // to 16 bits and adjust the bit resolution when converting later
    int16_t temperature = temperature_bits << 4;

    // shift the sample back down and convert by the TMP_101 bit resolution
    return ((temperature / 16) * 0.0625f);
}

 

要在沒有硬件的環境下測試它,需要編一個void __wrap_i2c_read_blocking()以取代讀物理設備的i2c_read_blocking(),然後在連接時指定它:--wrap=i2c_read_blocking -Wl。下麵這段程序測試負溫度下得程序運行:先用will_return()預存-25在mock_type中,然後assert_true()調用tmp101_get_tempearature(),繼而調用__wrap_i2c_read_blocking(),而後者返回mock_type的值。

讀取will——return
static void test_negative_temperature(void **state)
{
    will_return(__wrap_i2c_read_blocking, 0b11100111);
    will_return(__wrap_i2c_read_blocking, 0b00000000);

    assert_true(tmp101_get_temperature() == -25);
}

3.Unity

因ARM SCP用Unity和Mocka https://github.com/ARM-software/SCP-firmware/blob/master/unit_test/user_guide.md,看了下與Mocka類似啊:

https://blog.csdn.net/weifengdq/article/details/106221522? 

4. Other test tool

https://www.capterra.com/sem-compare/automated-testing-software/

https://en.m.wikipedia.org/wiki/List_of_unit_testing_frameworks 

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.