More Related Content
Similar to xUnitTestPattern/chapter7 (19)
More from ์ข
๋น ์ค (20)
xUnitTestPattern/chapter7
- 2. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 4. 1. ํ
์คํธ๋ฅผ ํ
์คํธ ๋ฉ์๋๋ก ๋ช
์
TEST(FactorialTest, Negative) {
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_TRUE(Factorial(-10) > 0);
}
- 5. 2. ๋จ์ธ ๋ฉ์๋assert method๋ก ๊ธฐ๋ ๊ฐ ๋ช
์
TEST(FactorialTest, Negative) {
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_TRUE(Factorial(-10) > 0);
}
๊ธฐ๋ ๊ฐ ์ค์ ๊ณ์ฐ๋ ๊ฐ
- 6. 3. ํ
์คํธ ์ค์ํธ์ ๋ชจ์๋๊ธฐ
BOOST_AUTO_TEST_SUITE (stringtest)
BOOST_AUTO_TEST_CASE (test1)
{
mystring s; stringtest ์ค์ํธ๋ฅผ
BOOST_CHECK(s.size() == 0); ์คํํ๋ฉด
}
test1, test2 ํ
์คํธ ์ผ์ด์ค
BOOST_AUTO_TEST_CASE (test2) ์คํ.
{
mystring s;
s.setbuffer("hello world");
BOOST_REQUIRE_EQUAL ('h', s[0]);
}
BOOST_AUTO_TEST_SUITE_END ()
- 7. 4. ํ
์คํธ ๊ฒฐ๊ณผ ๋ณด๊ณ ๋ฐ๊ธฐ
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
- 9. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 10. struct F {
F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
int i;
};
BOOST_FIXTURE_TEST_CASE( test_case1, F ) {
BOOST_CHECK( i == 1 );
++i;
}
BOOST_FIXTURE_TEST_CASE( test_case2, F ) {
BOOST_CHECK_EQUAL( i, 1 );
}
์ด ์์ค์ฝ๋๋ฅผ ์๋ก ๋ค์ด ์ค๋ช
ํ
์คํธ ํฝ์ค์ฒ ์ค์น
SUT ์คํ
๋จ์ธ ๋ฉ์๋ ํธ์ถ
ํ
์คํธ ํฝ์ค์ฒ ํด์ฒด
- 11. struct F {
F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
int i;
};
BOOST_FIXTURE_TEST_CASE( test_case1, F ) {
BOOST_CHECK( i == 1 );
++i;
}
BOOST_FIXTURE_TEST_CASE( test_case2, F ) {
BOOST_CHECK_EQUAL( i, 1 );
}
ํ
์คํธ ํฝ์ค์ฒ ์ค์น
์ธ๋ผ์ธ ์ค์น In-line Setup
์์ ์ค์น Delegated Setup
์๋ฌต์ ์ค์น Implicit Setup
- 12. struct F {
F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
int i;
};
BOOST_FIXTURE_TEST_CASE( test_case1, F ) {
BOOST_CHECK( i == 1 );
++i;
}
BOOST_FIXTURE_TEST_CASE( test_case2, F ) {
BOOST_CHECK_EQUAL( i, 1 );
} SUT ์คํ
- 13. struct F {
F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
int i;
};
BOOST_FIXTURE_TEST_CASE( test_case1, F ) {
BOOST_CHECK( i == 1 );
++i;
}
BOOST_FIXTURE_TEST_CASE( test_case2, F ) {
BOOST_CHECK_EQUAL( i, 1 );
}
ํ
์คํธ ํฝ์ค์ฒ ํด์ฒด
๊ฐ๋น์ง ์ปฌ๋ ์
ํด์ฒด Garbage-Collected Teardown
์ธ๋ผ์ธ ํด์ฒด In-line Teardown
์๋ฌต์ ํด์ฒด Implicit Teardown
์๋ ํด์ฒด Automated Teardown
- 14. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 15. SUT๋ฅผ ์คํํ๊ธฐ ์ํด ์ค๋นํด์ผ ํ๋ ๋ชจ๋ ๊ฒ
์ค์น, ํด์ฒด๋ฅผ ์ฑ
์์ง๋ค.
class FooTest : public ::testing::Test {
protected:
virtual void SetUp() { ... }
virtual void TearDown() { ... }
};
TEST_F(FooTest, Test1) {
...
}
TEST_F(FooTest, Test2) {
...
}
- 16. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 18. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 20. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 21. ํ
์คํธ ์คํ๊ธฐ์์ ํ
์คํธ ๋ฉ์๋๋ฅผ ์คํ.
๊ฐ์ ์คํ ํจ์๊ฐ ๋ค๋ฅด๋ค๋ฉด?
๋์ผํ ์ธํฐํ์ด์ค๋ก ํ
์คํธ ๋ฉ์๋๋ฅผ ์คํ.
Command ํจํด
๋์ผํ ์ธํฐํ์ด์ค๋ก ์คํ
โ๋ฌด์์ ์ด๋ป๊ฒโ๋ฅผ ์จ๊ธด๋ค
- 22. TEST(VectorTest, Clear) {
// ์ด์ฉ๊ณ ์ ์ฉ๊ณ ..
}
class VectorTest_Clear_Test : public ::testing::Test {
...
private:
virtual void TestBody() {
// ์ด์ฉ๊ณ ์ ์ฉ๊ณ ..
}
- 23. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 25. xUnit?
์ต์ํ ์์์ผ ํ ๊ฒ
ํ
์คํธ ์ ์
ํฝ์ค์ฒfixture?
์ค์ํธsuite ์ ์
ํ
์คํธ ์คํ, ๊ฒฐ๊ณผ
xUnit ๋ด๋ถ
ํ
์คํธ ๋ช
๋ น
ํ
์คํธ ์ค์ํธ ๊ฐ์ฒด
์ ์ฐจ์ ์ธ์์์์ xUnit
- 26. ์ ์ญ ํ๋ก์์ ์ธ ํ
์คํธ ๋ฉ์๋
ํ
์คํธ ์ค์ํธ ํ๋ก์์
ํ
์คํธ ๋ฉ์๋๋ค์ ๋ฐฐ์ด์ ์ธ์๋ก
๋ ์์ธํ ๋ด์ฉ์
Working Effectively with Legacy Code : Chapter 19 ์ฐธ๊ณ
- 27. reference
โข google test
โ http://code.google.com/p/googletest/
โข boost
โ http://www.boost.org/
โข ์คํ ์์ค C/C++ ์ ๋ ํ
์คํธ ๋๊ตฌ, Part 1
โ http://www.ibm.com/developerworks/kr/library/au-ctools1_boost/