java 및 .NET 용 JUnit 및 Nunit과 같은 C 용 유닛 테스트 프레임 워크가 있습니까? 또는 다른 시나리오에서 C로 작성된 코드를 테스트하려면 어떻게해야합니까? 사전에C 용 유닛 테스트 프레임 워크
감사합니다 ......
java 및 .NET 용 JUnit 및 Nunit과 같은 C 용 유닛 테스트 프레임 워크가 있습니까? 또는 다른 시나리오에서 C로 작성된 코드를 테스트하려면 어떻게해야합니까? 사전에C 용 유닛 테스트 프레임 워크
감사합니다 ......
: 여기
내 테스트 중 하나의 예입니다. GStreamer과 같은 몇 가지 큰 활성 프로젝트에서 사용됩니다. 다음은 간단한 실패 예입니다. 행의 경우 :fail_if (0 == get_element_position(spot), "Position should not be 0");
테스트 프레임 워크 : http://library.gnome.org/devel/glib/stable/glib-Testing.html
내가 단위 테스트 프레임 워크에 여전히 새로운 해요 하지만 최근에 cut, check 및 cunit을 사용해 보았습니다. 이것은 다른 사람들의 경험에 반하는 듯이 보였으 나 (이전 질문에 대해서는 Unit Testing C Code을 참조하십시오),하지만 저는 cunit이 가장 쉽게 얻을 수 있다는 것을 알았습니다. cunit은 다른 xunit 프레임 워크와 잘 조화되고 언어를 다소 자주 전환해야하기 때문에 이것은 나에게 좋은 선택 인 것 같습니다.
단위 테스트 C에 마지막으로 필요한 시간은 CuTest입니다.이 테스트는 단 하나의 .c/.h 쌍으로, 테스트 스위트와 어설 션을 빌드하기위한 모든 테스트를 자동으로 찾는 작은 쉘 스크립트와 함께 제공됩니다 오류가 전혀 도움이되지 않습니다. 내가 Check 및 설정에 매우 쉬운 몇 가지 일했다
void TestBadPaths(CuTest *tc) {
// Directory doesn't exist
char *path = (char *)"/foo/bar";
CuAssertPtrEquals(tc, NULL, searchpath(path, "sh"));
// A binary which isn't found
path = (char *)"/bin";
CuAssertPtrEquals(tc, NULL, searchpath(path, "foobar"));
}
Seatest는 내가 직접 작성한 것으로 오픈 소스입니다. 목표는 간단하고 깨끗한 구문을 사용하는 것입니다.
http://code.google.com/p/seatest/
것이 기본 간단한 테스트의 일종
...#include "seatest.h"
//
// create a test...
//
void test_hello_world()
{
char *s = "hello world!";
assert_string_equal("hello world!", s);
assert_string_contains("hello", s);
assert_string_doesnt_contain("goodbye", s);
assert_string_ends_with("!", s);
assert_string_starts_with("hell", s);
}
//
// put the test into a fixture...
//
void test_fixture_hello(void)
{
test_fixture_start();
run_test(test_hello_world);
test_fixture_end();
}
//
// put the fixture into a suite...
//
void all_tests(void)
{
test_fixture_hello();
}
//
// run the suite!
//
int main(int argc, char** argv)
{
run_tests(all_tests);
return 0;
}
도 매우 간단하고 BDD 프레임 워크를 사용하기 쉬운 cspec,있다. 만약 당신이 그것을 사용하는 사소한 것 RSpec에 또는 모카 같은 것을 사용한 경우
. main
기능을 쓰지 않아도됩니다. bdhar의 의견에
context (example) {
describe("Hello world") {
it("true should be true") {
should_bool(true) be equal to(true);
} end
it("true shouldn't be false") {
should_bool(true) not be equal to(false);
} end
it("this test will fail because 10 is not equal to 11") {
should_int(10) be equal to(11);
} end
skip("this test will fail because \"Hello\" is not \"Bye\"") {
should_string("Hello") be equal to("Bye");
} end
} end
}
http://www.google.com/search?q=unit+testing+c – bdhar
1 : 여기
은 예입니다. SO/Google 검색에 문제가있는 경우 단위 테스트는 걱정할 필요가없는 최소한의 것입니다 :-) – richsage적어도 두 개의 중복이 관련 링크에서 있습니다. – dmckee