我到目前爲止還沒有使用單元測試,我打算採用這個過程。 TDD給我留下了深刻的印象,當然也想嘗試一下 - 我幾乎可以肯定這是一條可行的路。使用Boost進行單元測試的最喜歡/推薦的項目結構和文件結構是什麼?
Boost看起來像一個不錯的選擇,主要是因爲它的維護。有了這個說法,我應該如何去實施一個工作和優雅的文件結構和項目結構?我在Win XP中使用VS 2005。我一直在使用Google,並且比開明更困惑。
我到目前爲止還沒有使用單元測試,我打算採用這個過程。 TDD給我留下了深刻的印象,當然也想嘗試一下 - 我幾乎可以肯定這是一條可行的路。使用Boost進行單元測試的最喜歡/推薦的項目結構和文件結構是什麼?
Boost看起來像一個不錯的選擇,主要是因爲它的維護。有了這個說法,我應該如何去實施一個工作和優雅的文件結構和項目結構?我在Win XP中使用VS 2005。我一直在使用Google,並且比開明更困惑。
我們的加速測試基於結構如下:
ProjectRoot/
Library1/
lib1.vcproj
lib1.cpp
classX.cpp
...
Library2/
lib2.vcproj
lib2.cpp
toolB.cpp
classY.cpp
...
MainExecutable/
main.cpp
toolA.cpp
toolB.cpp
classZ.cpp
...
Tests/
unittests.sln
ut_lib1/
ut_lib1.vcproj (referencing the lib1 project)
ut_lib1.cpp (with BOOST_AUTO_TEST_CASE) - testing public interface of lib1
ut_classX.cpp - testing of a class or other entity might be split
into a separate test file for size reasons or if the entity
is not part of the public interface of the library
...
ut_lib2/
ut_lib2.vcproj (referencing the lib2 project)
ut_lib2.cpp (with BOOST_AUTO_TEST_CASE) - testing public interface of lib2
...
ut_toolA/
ut_toolA.vcproj (referencing the toolA.cpp file)
ut_toolA.cpp - testing functions of toolA
ut_toolB/
ut_toolB.vcproj (referencing the toolB.cpp file)
ut_toolB.cpp - testing functions of toolB
ut_main/
ut_main.vcproj (referencing all required cpp files from the main project)
ut_classZ.cpp - testing classZ
...
被選定爲一個傳統項目,在這裏我們必須對什麼測試的情況下,逐案決定這種結構添加和如何爲源代碼的現有模塊提供組測試項目。
注意事項:
在我們的真實(C++)世界中,您必須權衡btw。遺留問題,開發者便利,編譯時間等。我認爲我們的項目結構是一個很好的折衷。 :-)
我把我的核心代碼放到.libs或.dlls中,然後讓我的Boost測試項目依賴於這些lib/dll項目。所以,我可能最終:
ProjectRoot
Lib1Source
Lib1Tests
Lib2Source
Lib2Tests
另一種方法是你的源存儲在一個單獨的文件夾和文件添加到您的主應用項目和單元測試項目都但我覺得這有點凌亂。因人而異。
替代方案非常容易出錯! – Wartin 2010-06-03 13:11:50
ProjectRoot依賴關係如何? ProjectRoot是否有一個ProjectRootTests取決於所有其他測試? – JBRWilkinson 2010-08-25 09:46:04