mockEditor::mockEditor()
{
m_arMovieList.Add("Star Wars");
m_arMovieList.Add("Star Trek");
m_arMovieList.Add("Stargate");
}
我们添加了三个影片用于测试。接着,应该把这个MockObjects的一个实例传递给需要测试的模块。这里就是我们要测试的UI(MovieListWindow)。
m_pEditor = new mockEditor();
MovieListWindow *pWindow = new MovieListWindow(m_pEditor);
最后我们来看看经过修改后的新的测试添加影片的方法:
void TestOperation::testAdd()
{
//拷贝一份movie list
CStringArray MovieNamesWithAddition;
for(int n=0; n { MovieNamesWithAddition.Add(m_MovieNames.GetAt(n)); } MovieNamesWithAddition.Add(LOST_IN_SPACE); //生成窗口 MovieListWindow *pWindow = new MovieListWindow(m_pEditor); pWindow->Init(); //填写新的影片的名称 CEdit* pEdit = pWindow->GetMovieField(); pEdit->SetWindowText(LOST_IN_SPACE); //点击add btn CButton* pBtn = pWindow->GetAddButton(); ::SendMessage(pBtn->m_hWnd, BM_CLICK, 0, 0); //检查列表控件中是否已加入新的影片 CListBox* pListBox = pWindow->GetMovieListBox(); CPPUNIT_ASSERT_EQUAL(MovieNamesWithAddition.GetSize(), pListBox->GetCount());
文章来源于领测软件测试网 https://www.ltesting.net/