ã¯ããã«
ãåä½ãã¹ããå¹ççã«è¡ãããããã¹ã対象ã¨ãªãè¨èªã«å¿ãã¦ãã¾ãã¾ãªãã¬ã¼ã ã¯ã¼ã¯ãxUnitãããªãªã¼ã¹ããã¦ãã¾ããä¾ãã°JavaãªãJUnitã.NETãªãNUnitãCãªãCUnitãC++ãªãCppUnitããããããããã®ä»£è¡¨æ ¼ã¨ãã£ãã¨ããã§ããããã
ããã¤ã¯ãã½ããã®ãªã³ã©ã¤ã³ãã¬ã¸ã³ãMSDNãã¬ã¸ã³2008å¹´2æå·ãã§ãWindowsç°å¢ã«ç¹åããC/C++対å¿ã®åä½ãã¹ããã¬ã¼ã ã¯ã¼ã¯ãWinUnitããç´¹ä»ããã¦ãã¾ããå®è¡ç°å¢ãWindowsã«éå®ããã¦ã¯ãããã®ã®ããããè£ã£ã¦ä½ããã使ãåæã®è¯ããå®ç¾ãã¦ãã¾ãã
CUnit/CppUnitã®åé¡ç¹
ãCUnitã«ããåä½ãã¹ãã®ä¾ã示ãã¾ãã
#include <CUnit.h> #include "Car.h" #include <stdio.h> Car c; int car_setup(void) { c = car_new(50,2); return c != NULL ? 0 : 1; } int car_teardown(void) { car_delete(c); return 0; } void test_car_init(void) { CU_ASSERT_EQUAL(car_distance(c), 0); CU_ASSERT_EQUAL(car_remain(c), 0); } void test_car_refuel(void) { car_refuel(c, 20); CU_ASSERT_EQUAL(car_remain(c), 20); car_refuel(c, 20); CU_ASSERT_EQUAL(car_remain(c), 40); car_refuel(c, 20); CU_ASSERT_EQUAL(car_remain(c), 50); } /* * test-suitã®æ§ç¯ã¨å®è¡ */ static CU_TestInfo test_car[] = { { "åæå", test_car_init }, { "給油", test_car_refuel }, CU_TEST_INFO_NULL, }; static CU_SuiteInfo suites[] = { { "Carã®ãã¹ã", car_setup, car_teardown, test_car }, CU_SUITE_INFO_NULL, }; #include <Basic.h> int main() { CU_initialize_registry(); CU_register_suites(suites); CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); CU_cleanup_registry(); return 0; }
ããã®ã³ã¼ããä¸ã»ã©ã®/* --- */
以éã®é¨åã¯ãã¹ããã®ãã®ã§ã¯ããã¾ãããããã¤ãã®ãã¹ãé¢æ°ãã¾ã¨ããã¹ã¤ã¼ããçµã¿ä¸ããã¹ã¤ã¼ãå
ã®ãã¹ãé¢æ°ãé ã«å¼ã³åºãã¦ã¯ãã®çµæãåéããï¼ã©ã¤ãã©ãªæä¾ã®ï¼å®è¡ã«ã¼ãã³ãèµ·åãã¦ãã¾ãããã¹ãã®è¿½å /åé¤ãããã¯ãã¹ãé¢æ°åã®å¤æ´ã«ä¼´ã£ã¦ã¹ã¤ã¼ãçµã¿ä¸ãé¨ã®ä¿®æ£ãå¿
è¦ã¨ãªãã¾ãããã®ããã¹ã¤ã¼ãã®ä¿®æ£æ¼ããããã¨ãã³ã³ãã¤ã«/ãªã³ã¯ã¨ã©ã¼ã¨ãªã£ããã追å ãããã¹ããå®è¡ããã¾ããã
ãããããã¡ãã¯åããã¹ããNUnitï¼C++/CLIï¼ã§æ¸ãããã®ãã¹ã¤ã¼ãã®çµã¿ä¸ãããã¹ãå®è¡é¨ãããã¾ããã
#include "Car.h" using namespace System; using namespace NUnit::Framework; using namespace NUnit::Framework::SyntaxHelpers; namespace TestByNUnit { [TestFixture] public ref class CarTest { Car c; public: [SetUp] void SetUp() { c = car_new(50,2); } [TearDown] void TearDown() { car_delete(c); } [Test] void init() { Assert::That(car_distance(c), Is::EqualTo(0)); Assert::That(car_remain(c), Is::EqualTo(0)); } [Test] void refuel() { car_refuel(c, 20); Assert::That(car_remain(c), Is::EqualTo(20)); car_refuel(c, 20); Assert::That(car_remain(c), Is::EqualTo(40)); car_refuel(c, 20); Assert::That(car_remain(c), Is::EqualTo(50)); } }; }
ãJavaã.NETã«ã¯çæããããã¤ãã³ã¼ããã¢ã»ã³ããªããã¯ã©ã¹åãã¡ã½ããåãå¼æ°ãªã©ãæ½åºããã¤ã³ã¹ã¿ã³ã¹ã®çæã¨ã¡ã½ããã®å¼ã³åºããå¯è½ã§ããJUnitãNUnitã¯ããªãã¬ã¯ã·ã§ã³ãã¨å¼ã°ãããã®æ©è½ã使ã£ã¦ãã¹ããæ½åº/å®è¡ã§ããã®ã§ããããã¤ãã£ãã³ã¼ããçæããC/C++ã¯ãªãã¬ã¯ã·ã§ã³ãæã¡åããã¦ããªãã®ã§ããã¹ãã¹ã¤ã¼ãã®çµã¿ç«ã¦ããã³ãã¹ãã®å®è¡ãã½ã¼ã¹ã³ã¼ãå ã«ç½®ãã¦ãããªããã°ãªãã¾ããã
ãæ¬ç¨¿ã§ç´¹ä»ããWinUnitã¯ãã¹ãã³ã¼ãããDLLãçæãããã¨ã§ï¼ç°¡æçã®ï¼ãªãã¬ã¯ã·ã§ã³ãå®ç¾ãã¦ãã¾ããDLLã¯ä»ã®EXEãDLLããå¼ã³åºãããããé¢æ°åããã®å
é¨ã«åãè¾¼ã¾ãã¦ãã¾ããWinUnitã®ãã¹ãå®è¡ã¢ããªã±ã¼ã·ã§ã³ãWinUnit.exeãã¯ãå®è¡æã«æå®ãããDLLå
ãããã¹ãé¢æ°ãæ½åºãå¼ã³åºãã¦ãããã®ã§ããã¹ãã³ã¼ãä¸ã®ã¹ã¤ã¼ãçµã¿ä¸ãããã¹ãå®è¡é¨ï¼ããªãã¡main
ï¼ãå¿
è¦ã¨ããªãã®ã§ãã
ãWindowsã¨ããéãããç°å¢ã«éå®ããããã®ã®ãCUnitãCppUnitã«æ¯ã¹ä½¿ãå¿å°/ãæ軽ãã大ããåä¸ãã¦ãã¾ãã