0
目前我做這種方式(僞):如何測試客戶端 - 服務器與升壓流動::測試
#include <boost/test/unit_test.hpp>
#include <string>
bool testingClient = true;
BOOST_AUTO_TEST_SUITE(ProtocolSchema)
BOOST_AUTO_TEST_CASE(server)
{
testingClient = false;
// start server listener
FILE *client_stdout = popen((argv[0] + std::string(" --run_test=ProtocolSchema/client 2>&1")).c_str(), "r");
for (1000ms)
{
// listen for ping, reply with a pong
}
pclose(fl);
}
BOOST_AUTO_TEST_CASE(client)
{
if (!testingClient)
return;
// send ping to the server
// check that it replies with a pong
}
}
的想法很明確:boost::test
運行測試順序,一旦它試圖運行服務器時,服務器單元測試翻轉testingClient
這種方式下一個測試根本不會做任何事情並退出。服務器測試啓動相同的測試可執行文件run_test
arg設置爲僅運行客戶端測試。在第二個過程中testingClient
標誌不翻轉,這使得它實際上運行客戶端測試。
有沒有一種正確的方法來做這種客戶端 - 服務器單元測試與boost :: test?在我的情況下,所有來自客戶端進程的測試日誌都會丟失:我需要將它們從client_stdout中解脫出來,然後將它們寫入BOOST_MESSAGE?
看起來你肯定可以使用[賽事](http://www.boost.org/doc/libs/1_63_0/libs/test/doc/html/ boost_test/tests_organization/fixtures.html)。 –
我們使用它們,但這對我來說無濟於事。它與啓動單獨的進程沒有關係(我不能在同一進程中運行它們) – Pavel