ThrowTheSwitch/Unity là dự án C với 5.5k sao trong nhóm Backend. Simple unit testing for C
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Copyright (c) 2007 - 2026 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 be 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.
You can also find the change log and known issues in our documentation.
Getting Started
The docs folder contains a getting started guide and much more tips about using Unity.
Unity Assertion Summary
For the full list, see 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.
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, you can use a specific version.
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 affect 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:
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:
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.
Asserts that the actual value is less than or greater than the threshold.
There are also LESS_OR_EQUAL and GREATER_OR_EQUAL variations.
These obey the same rules for equality as do TEST_ASSERT_EQUAL_FLOAT and TEST_ASSERT_EQUAL_DOUBLE:
If the two values are within a small % delta of the expected value, the assertion will pass.
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.
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.
ThrowTheSwitch/Unity thuộc nhóm Backend trên TopGit, cùng 2 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về ThrowTheSwitch/Unity ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/ThrowTheSwitch/Unity là nguồn chính thức.
ThrowTheSwitch/Unity có bao nhiêu sao?
ThrowTheSwitch/Unity có 5.5k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/ThrowTheSwitch/Unity. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
ThrowTheSwitch/Unity có phải mã nguồn mở không?
Có — ThrowTheSwitch/Unity phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/ThrowTheSwitch/Unity.
ThrowTheSwitch/Unity còn đang phát triển không?
Commit gần nhất trên ThrowTheSwitch/Unity là 17 ngày trước (theo timestamp GitHub). Repo có 1.1k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
ThrowTheSwitch/Unity dùng license gì?
ThrowTheSwitch/Unity phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
ThrowTheSwitch/Unity là gì?
ThrowTheSwitch/Unity (ThrowTheSwitch/Unity) là dự án C trên GitHub. Theo mô tả gốc: Simple unit testing for C
ThrowTheSwitch/Unity viết bằng ngôn ngữ gì?
ThrowTheSwitch/Unity chủ yếu viết bằng C. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về Unity?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về Unity.