Skip to content

Commit

Permalink
CppUMockを使ったテストに変更
Browse files Browse the repository at this point in the history
  • Loading branch information
grace2riku committed Sep 28, 2023
1 parent 984057f commit f94b098
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/settingvalue_example/SettingValueExampleTest.cpp
Expand Up @@ -3,6 +3,7 @@ extern "C"
}

#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"

#include <iostream>
using namespace std;
Expand All @@ -21,12 +22,22 @@ TEST_GROUP(SettingValueExampleTest)

void teardown()
{
mock().clear();
delete settingValueValidation;
}
};

TEST(SettingValueExampleTest, SettingValueinValid)
{
mock().expectOneCall("read").andReturnValue(99);

CHECK_FALSE(settingValueValidation->validate());
}

TEST(SettingValueExampleTest, SettingValueValid)
{
mock().expectOneCall("read").andReturnValue(100);

CHECK(settingValueValidation->validate());
}

Expand Up @@ -3,6 +3,9 @@
#include <iostream>
using namespace std;

#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"

// コンストラクタの実装
SettingValueMock::SettingValueMock() {
cout << "SettingValueMock constructor" << endl;
Expand All @@ -16,5 +19,6 @@ void SettingValueMock::write() {
}

int SettingValueMock::read() {
return 100;
return mock().actualCall("read").returnIntValue();
// return 100;
}

0 comments on commit f94b098

Please sign in to comment.