Unit Test
姓名學最佳筆畫數為例
Author : Juggernaut Liu
Outline
● Testing framework
● Project Introduction
● Implement Process
● Demo
● Notes
● Reference
Testing framework
● Coding
○ c++
● Googletest
○ https://code.google.com/p/googletest/
● Googlemock
○ https://code.google.com/p/googlemock/
Project Introduction
● 姓名學 - 如何取名
○ http://juggernaut-liu.blogspot.tw/2013/09/rule-1-rule-2-1-2-rule-3-15-x-
6-15-x-6.html
● Project Scope
○ Input : 姓筆畫, 缺五行type
○ Rules:
■ 總格補上缺乏的五行
■ 三才配置
■ 八十一數之靈動
○ Ouput: 用vector存的最佳筆畫數組合
Project Introduction(2)
● CalculateChineseNameProcessor
○ main algorithm
● UnitTest
○ unit test for CalculateChineseNameProcessor
Project Introduction(3)
CalculateChineseNameProcessor
● NameProfile
○ Data structure
● ILoadSettings
○ Loading config from text
● IDataProducer
○ Produce initial data (A lot of NameProfile)
● IRulefilter
○ Each Rulefilter filter out not-matching NameProfiles
● MainProcessor
○ Run all process
Project Introduction(4) class diagram
Implement Process
Steps
1, Design one Interface
2, Write the Unit Test
3, Write the production code
4, Modify interface or test to match the code.
5, Repeat 1,2,3,4 to next feature.
Implement Process(2)
Implement order
1, NameProfile
2, IDataProducer
3, IRuleFilter
4, ILoadSettings
5, MainProcessor
Demo
Notes
● I do not test private code, but I test the public
code which call private code
● TEST vs TEST_F
● SetUpTestCase, TearDownTestCase vs
SetUp, TearDown
● ::testing::FLAGS_gtest_output = "xml:" =>log
Notes(2)
● Each unit test pass the test, but it test error
when I combine them
○ Got 1 bug
● Test sample is too few to test all conditions
○ Miss some conditions
Reference
GitHub
https://github.com/JuggernautLiu/CalculateChineseNameNumber
MyBlog
http://juggernaut-liu.blogspot.tw/2013/09/rule-1-rule-2-1-2-rule-3-15-x-6-15-x-6.
html
Googletest
https://code.google.com/p/googletest/
Googlmock
https://code.google.com/p/googlemock/

Unit test demo for calculatechinesenamenumber