Unity Test ![CI](https://github.com/ThrowTheSwitch/Unity/workflows/CI/badge.svg)
==========
__Copyright (c) 2007 - 2021 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
Welcome to the Unity Test Project, one of the main projects of ThrowTheSwitch.org. Unity Test is a
unit testing framework built for C, with a focus on working with embedded toolchains.
This project is made to test code targetting microcontrollers big and small. The core project is a
single C file and a pair of headers, allowing it to the added to your existing build setup without
too much headache. You may use any compiler you wish, and may use most existing build systems
including make, cmake, etc. If you'd like to leave the hard work to us, you might be interested
in Ceedling, a build tool also by ThrowTheSwitch.org.
If you're new to Unity, we encourage you to tour the [getting started guide](docs/UnityGettingStartedGuide.md)
Getting Started
===============
The [docs](docs/) folder contains a [getting started guide](docs/UnityGettingStartedGuide.md)
and much more tips about using Unity.
Unity Assertion Summary
=======================
For the full list, see [UnityAssertionsReference.md](docs/UnityAssertionsReference.md).
Basic Validity Tests
--------------------
TEST_ASSERT_TRUE(condition)
Evaluates whatever code is in condition and fails if it evaluates to false
TEST_ASSERT_FALSE(condition)
Evaluates whatever code is in condition and fails if it evaluates to true
TEST_ASSERT(condition)
Another way of calling `TEST_ASSERT_TRUE`
TEST_ASSERT_UNLESS(condition)
Another way of calling `TEST_ASSERT_FALSE`
TEST_FAIL()
TEST_FAIL_MESSAGE(message)
This test is automatically marked as a failure. The message is output stating why.
Numerical Assertions: Integers
------------------------------
TEST_ASSERT_EQUAL_INT(expected, actual)
TEST_ASSERT_EQUAL_INT8(expected, actual)
TEST_ASSERT_EQUAL_INT16(expected, actual)
TEST_ASSERT_EQUAL_INT32(expected, actual)
TEST_ASSERT_EQUAL_INT64(expected, actual)
Compare two integers for equality and display errors as signed integers. A cast will be performed
to your natural integer size so often this can just be used. When you need to specify the exact size,
like when comparing arrays, you can use a specific version:
TEST_ASSERT_EQUAL_UINT(expected, actual)
TEST_ASSERT_EQUAL_UINT8(expected, actual)
TEST_ASSERT_EQUAL_UINT16(expected, actual)
TEST_ASSERT_EQUAL_UINT32(expected, actual)
TEST_ASSERT_EQUAL_UINT64(expected, actual)
Compare two integers for equality and display errors as unsigned integers. Like INT, there are
variants for different sizes also.
TEST_ASSERT_EQUAL_HEX(expected, actual)
TEST_ASSERT_EQUAL_HEX8(expected, actual)
TEST_ASSERT_EQUAL_HEX16(expected, actual)
TEST_ASSERT_EQUAL_HEX32(expected, actual)
TEST_ASSERT_EQUAL_HEX64(expected, actual)
Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons,
you can specify the size... here the size will also effect how many nibbles are shown (for example, `HEX16`
will show 4 nibbles).
TEST_ASSERT_EQUAL(expected, actual)
Another way of calling TEST_ASSERT_EQUAL_INT
TEST_ASSERT_INT_WITHIN(delta, expected, actual)
Asserts that the actual value is within plus or minus delta of the expected value. This also comes in
size specific variants.
TEST_ASSERT_GREATER_THAN(threshold, actual)
Asserts that the actual value is greater than the threshold. This also comes in size specific variants.
TEST_ASSERT_LESS_THAN(threshold, actual)
Asserts that the actual value is less than the threshold. This also comes in size specific variants.
Arrays
------
_ARRAY
You can append `_ARRAY` to any of these macros to make an array comparison of that type. Here you will
need to care a bit more about the actual size of the value being checked. You will also specify an
additional argument which is the number of elements to compare. For example:
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, elements)
_EACH_EQUAL
Another array comparison option is to check that EVERY element of an array is equal to a single expected
value. You do this by specifying the EACH_EQUAL macro. For example:
TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, elements)
Numerical Assertions: Bitwise
-----------------------------
TEST_ASSERT_BITS(mask, expected, actual)
Use an integer mask to specify which bits should be compared between two other integers. High bits in the mask are compared, low bits ignored.
TEST_ASSERT_BITS_HIGH(mask, actual)
Use an integer mask to specify which bits should be inspected to determine if they are all set high. High bits in the mask are compared, low bits ignored.
TEST_ASSERT_BITS_LOW(mask, actual)
Use an integer mask to specify which bits should be inspected to determine if they are all set low. High bits in the mask are compared, low bits ignored.
TEST_ASSERT_BIT_HIGH(bit, actual)
Test a single bit and verify that it is high. The bit is specified 0-31 for a 32-bit integer.
TEST_ASSERT_BIT_LOW(bit, actual)
Test a single bit and verify that it is low. The bit is specified 0-31 for a 32-bit integer.
Numerical Assertions: Floats
----------------------------
TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual)
Asserts that the actual value is within plus or minus delta of the expected value.
TEST_ASSERT_EQUAL_FLOAT(expected, actual)
TEST_ASSERT_EQUAL_DOUBLE(expected, actual)
Asserts that two floating point values are "equal" within a small % delta of the expected value.
String Assertions
-----------------
TEST_ASSERT_EQUAL_STRING(expected, actual)
Compare two null-terminate strings. Fail if any character is different or if the lengths are different.
TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len)
Compare two strings. Fail if any character is different, stop comparing after len characters.
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message)
Compare two null-terminate strings. Fail if any character is different or if the lengths are different. Output a custom message on failure.
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message)
Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure.
Pointer Assertions
------------------
Most pointer operations can be performed by simply using the integer comparisons above. However, a couple of special cases are added for clarity.
TEST_ASSERT_NULL(pointer)
Fails if the pointer is not equal to NULL
TEST_ASSERT_NOT_NULL(pointer)
Fails if the pointer is equal to NULL
Memory Assertions
-----------------
TEST_ASSERT_EQUAL_MEMORY(expected, actual, len)
Compare two blocks of memory. This is a good generic assertion for types that can't be coerced into acting like
standard types... but since it's a memory compare, you have to be careful that your data types are packed.
\_MESSAGE
---------
you can append \_MESSAGE to any of the macros to make them take an additional argument. This argument
is a string that will be printed at the end of the failure strings. This is useful for specifying more
information about the problem.
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
以ESP32为主控的LED与OLED驱动代码 (190个子文件)
libFrameworkArduino.a 3.09MB
firmware.bin 250KB
partitions.bin 3KB
meson.build 544B
meson.build 539B
meson.build 361B
meson.build 282B
meson.build 260B
meson.build 159B
unity.c 64KB
oled.c 12KB
TestProductionCode.c 2KB
TestProductionCode.c 2KB
TestProductionCode.c 2KB
TestProductionCode.c 2KB
TestProductionCode_Runner.c 2KB
TestProductionCode_Runner.c 2KB
TestProductionCode2_Runner.c 1KB
TestProductionCode2_Runner.c 1KB
ProductionCode.c 857B
ProductionCode.c 857B
ProductionCode.c 846B
ProductionCode.c 846B
TestProductionCode2.c 700B
TestProductionCode_Runner.c 700B
TestProductionCode2.c 664B
TestProductionCode2.c 567B
TestProductionCode2.c 565B
UnityHelper.c 405B
ProductionCode2.c 335B
ProductionCode2.c 335B
ProductionCode2.c 331B
ProductionCode2.c 331B
TestProductionCode2_Runner.c 271B
all_tests.c 221B
project.checksum 40B
unityConfig.cmake 54B
main.cpp 417B
esp32-hal-time.c.d 17KB
esp32-hal-misc.c.d 16KB
Esp.cpp.d 16KB
main.cpp.d 15KB
base64.cpp.d 15KB
MD5Builder.cpp.d 15KB
FunctionalInterrupt.cpp.d 15KB
IPv6Address.cpp.d 15KB
StreamString.cpp.d 15KB
IPAddress.cpp.d 15KB
Stream.cpp.d 15KB
Print.cpp.d 15KB
WString.cpp.d 15KB
Tone.cpp.d 15KB
main.cpp.d 15KB
esp32-hal-cpu.c.d 14KB
esp32-hal-gpio.c.d 14KB
esp32-hal-spi.c.d 14KB
esp32-hal-uart.c.d 13KB
esp32-hal-i2c.c.d 13KB
HardwareSerial.cpp.d 13KB
esp32-hal-timer.c.d 13KB
esp32-hal-adc.c.d 13KB
esp32-hal-sigmadelta.c.d 13KB
wiring_shift.c.d 13KB
wiring_pulse.c.d 13KB
oled.c.d 12KB
esp32-hal-ledc.c.d 12KB
esp32-hal-rmt.c.d 12KB
esp32-hal-dac.c.d 12KB
esp32-hal-bt.c.d 12KB
esp32-hal-touch.c.d 12KB
esp32-hal-rgb-led.c.d 12KB
esp32-hal-matrix.c.d 12KB
esp32-hal-psram.c.d 12KB
esp32-hal-i2c-slave.c.d 11KB
WMath.cpp.d 2KB
stdlib_noniso.c.d 1KB
FirmwareMSC.cpp.d 443B
USBMSC.cpp.d 340B
USBCDC.cpp.d 337B
HWCDC.cpp.d 335B
USB.cpp.d 331B
esp32-hal-tinyusb.c.d 270B
firmware_msc_fat.c.d 254B
cencode.c.d 248B
cdecode.c.d 248B
cbuf.cpp.d 222B
.sconsign38.dblite 888KB
.editorconfig 583B
firmware.elf 5.29MB
run_test.erb 969B
.gitattributes 590B
.gitignore 288B
.gitignore 94B
unity.h 87KB
unity_internals.h 85KB
oled_font.h 84KB
unity_config.h 12KB
oled.h 2KB
UnityHelper.h 483B
ProductionCode.h 96B
共 190 条
- 1
- 2
Elec实验室
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0