2009 (2)
2010 (1)
2014 (58)
2015 (74)
2016 (71)
2017 (67)
2018 (37)
2020 (57)
2021 (47)
2022 (69)
2023 (45)
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