E D R , A S I H C RSS

Gui Testing With Mfc

CppUnit „ ดšฉํ•œ MFC —„œ˜ GuiTesting (‹œ„ค‘. ฒฐŠ”?)

Dialog Based —„œ˜ ํ…ŒŠคํŠธ

Dialog Based ˜ ฒฝšฐ Modal Dialog ดšฉํ•˜ฒŒ œ‹ค. ด ฒฝšฐ Dialog ‚ด—„œงŒ ฉ”„€ฃจํ”„€ ž‘™ํ•˜ฒŒ ˜€กœ, DoModal ํ•จˆ˜กœ ‹คด–กœทธ „šด ดํ›„˜ ฝ”“œŠ” ํ•ด‹ Dialog € ‹ซํžˆธฐ  „Œ€Š” ‹คํ–‰˜€ •ŠŠ”‹ค. ณ กœ, CppUnit —„œ˜ fixture ฆฌ ตฌ„ํ•˜—ฌ “ธ ˆ˜ —†‹ค.

ทธž˜„œ, ํ…ŒŠคํŠธ ‹œ„ํ• •Œ Modaless Dialog กœ งŒ“คณ  ‹คํ—˜„ ํ•˜˜€‹ค.


›ํ•˜Š” ž‘™ ชจŠต€ ด ‡‹ค.
  1. Editbox — •„ฌด €„ „ณ 
  2. Add „ํŠ„ ˆ„ฅดฉด
  3. List box — Editbox — “ด €ด ˆœ„œŒ€กœ ฒ˜Œ€„„›Œ€ณ 
  4. List box —„œ˜ ปค„œŠ” „›Œ„ €— œ„˜ํ•œ‹ค.
  5. List box — ฐ’ด „›Œ€ณ  ‚œ ’ค, Editbox ˜ €€ €›Œ„‹ค.

1. GUI Runner Setting

ดŠ” App ํดž˜Šค˜ InitInstance ํ•จˆ˜—„œ ํ•ด€‹ค.

~cpp 
#include "stdafx.h"
#include "GuiTestingOne.h"
#include "GuiTestingOneDlg.h"

#include "cppunit\ui\mfc\TestRunner.h"

#include "GuiTestCase.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(CGuiTestingOneApp, CWinApp)
	//{{AFX_MSG_MAP(CGuiTestingOneApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

CGuiTestingOneApp::CGuiTestingOneApp()
{
}

CGuiTestingOneApp theApp;

BOOL CGuiTestingOneApp::InitInstance()
{
	AfxEnableControlContainer();

	CppUnit::MfcUi::TestRunner runner;
	runner.addTest (GuiTestCase::suite());
	runner.run();

/* --- Test Runner งŒ ‹คํ–‰˜„ก, ‹คด–กœทธ „šฐŠ” €„„ ‹จ ง‰•„‘”‹ค. งˆ€ง‰— ‹คํ–‰ํ• •Œ ด €„˜ „ฒ˜ฆฌ œ €„„ ํ’€–ดฉด œ‹ค.
#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CGuiTestingOneDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
	}
	else if (nResponse == IDCANCEL)
	{
	}
*/
	return FALSE;
}

2. Test Case ˜ ž‘„


1. —ฐŠต

‹จ,  œŒ€กœ ž‘™ํ•˜Š”€ •Œ•„ณดธฐ œ„ํ•ด —ฐŠตฒธ m_bFlag €ˆ˜ งŒ“ค–ด„œ ํ…ŒŠคํŠธ ํ–ˆ‹ค.

ํ…ŒŠคํŠธ ํ†ต‹œ ˜ˆƒ˜Š” ฒฐ
test1One —ฐŠตฒธ Assert Equals. 10 == 10
test2GuiOne „ํŠด ˆŒŸฌกŒ„ ฒฝšฐ— CGuiTestingOneDlg::m_bFlag € true ƒํƒœ€ œ‹ค.

~cpp 
#include <cppunit/TestCase.h>
#include <cppunit/Extensions/HelperMacros.h>

#include "stdafx.h"                                  // resource, mfc  ดšฉํ•  ˆ˜ žˆ‹ค.
#include "GuiTestingOneDlg.h"                        // import GuiTestingOneDlg 

class GuiTestCase : public CppUnit::TestCase {
	CPPUNIT_TEST_SUITE(GuiTestCase);
	CPPUNIT_TEST ( test1One );
	CPPUNIT_TEST ( test2GuiOne );
	CPPUNIT_TEST ( test3ListAdd );
	CPPUNIT_TEST_SUITE_END();

public:
	CGuiTestingOneDlg* pDlg;
	void setUp () {
		pDlg = new CGuiTestingOneDlg();
		pDlg->Create(IDD_GUITESTINGONE_DIALOG);
	}

	void tearDown () {
		delete pDlg;
	}

public:
	void test1One () {
		CPPUNIT_ASSERT_EQUAL (10, 10);
	}

	void test2GuiOne () {

		pDlg->OnButtonadd();
		CPPUNIT_ASSERT_EQUAL (true, pDlg->m_bFlag);
	}
};

ฝ”“œ ถ”€
~cpp 
void CGuiTestingOneDlg::OnButtonadd() 
{
	// TODO: Add your control notification handler code here
	m_bFlag = true;
}

2. ํ…ŠคํŠธ ถ”€

ํ…ŒŠคํŠธ ํ†ต‹œ ˜ˆƒ˜Š” ฒฐ
test1One —ฐŠตฒธ Assert Equals. 10 == 10
test2GuiOne „ํŠด ˆŒŸฌกŒ„ ฒฝšฐ— CGuiTestingOneDlg::m_bFlag € true ƒํƒœ€ œ‹ค.
test3ListAdd Editbox — "Testing..." „ …‹ํŒ…. „ํŠ„ ˆŒ €„ •Œ Listbox ˜ item ˆ˜€ 1ฐœž„„ ํ™•ธ
. Listbox ˜ ฒซฒˆงธ item ˜ ŠคํŠธงด "Testing..." ž„„ ํ™•ธ

~cpp 
	void test3ListAdd () {
		pDlg->m_ctlEdit.SetWindowText("Testing...");
		pDlg->OnButtonadd();
		CPPUNIT_ASSERT_EQUAL (1, pDlg->m_ctlList.GetCount());
		CString str;

		pDlg->m_ctlList.GetText(0, str);
		CPPUNIT_ASSERT ( isSameString(str, "Testing..."));
	}

	bool isSameString (CString& str1, PSTR str2) {
		return str1.Compare(str2) == 0;
	}
};

ฝ”“œ ถ”€
~cpp 
void CGuiTestingOneDlg::OnButtonadd() 
{
	// TODO: Add your control notification handler code here
	m_bFlag = true;
	CString str;
	m_ctlEdit.GetWindowText(str);
	m_ctlList.AddString(str);
}

3. more...

ํ…ŒŠคํŠธ ํ†ต‹œ ˜ˆƒ˜Š” ฒฐ
test1One —ฐŠตฒธ Assert Equals. 10 == 10
test2GuiOne „ํŠด ˆŒŸฌกŒ„ ฒฝšฐ— CGuiTestingOneDlg::m_bFlag € true ƒํƒœ€ œ‹ค.
test3ListAdd Editbox — "Testing..." „ …‹ํŒ…. „ํŠ„ ˆŒ €„ •Œ Listbox ˜ item ˆ˜€ 1ฐœž„„ ํ™•ธ
. Listbox ˜ ฒซฒˆงธ item ˜ ฌธž—ดด "Testing..." ž„„ ํ™•ธ
test4ListAddMore test3 — ถ”€œ ํ˜•ํƒœ. Editbox — ‹ค‹œ "Testing2..." …‹ํŒ…ํ•˜ณ , „ํŠ„ ˆŒ €„ •Œ Listbox ˜ item ˆ˜€ 2ฐœž„„ ํ™•ธ
. Listbox ˜ ‘ฒˆงธ item ˜ ฌธž—ดด "Testing2..." ž„„ ํ™•ธ

~cpp 
	void test4ListAddMore () {
		test3ListAdd();
		CString str;

		pDlg->m_ctlEdit.SetWindowText("Testing2...");
		pDlg->OnButtonadd();
		CPPUNIT_ASSERT_EQUAL (2, pDlg->m_ctlList.GetCount());
		pDlg->m_ctlList.GetText(1, str);
		CPPUNIT_ASSERT ( isSameString(str, "Testing2..."));
	}

4. 'List box —„œ˜ ปค„œŠ” „›Œ„ €— œ„˜ํ•œ‹ค' — Œ€ํ•œ ํ…ŒŠคํŠธ

ํ…ŒŠคํŠธ ํ†ต‹œ ˜ˆƒ˜Š” ฒฐ
test1One —ฐŠตฒธ Assert Equals. 10 == 10
test2GuiOne „ํŠด ˆŒŸฌกŒ„ ฒฝšฐ— CGuiTestingOneDlg::m_bFlag € true ƒํƒœ€ œ‹ค.
test3ListAdd Editbox — "Testing..." „ …‹ํŒ…. „ํŠ„ ˆŒ €„ •Œ Listbox ˜ item ˆ˜€ 1ฐœž„„ ํ™•ธ
. Listbox ˜ ฒซฒˆงธ item ˜ ฌธž—ดด "Testing..." ž„„ ํ™•ธ
test4ListAddMore test3 — ถ”€œ ํ˜•ํƒœ. Editbox — ‹ค‹œ "Testing2..." …‹ํŒ…ํ•˜ณ , „ํŠ„ ˆŒ €„ •Œ Listbox ˜ item ˆ˜€ 2ฐœž„„ ํ™•ธ
. Listbox ˜ ‘ฒˆงธ item ˜ ฌธž—ดด "Testing2..." ž„„ ํ™•ธ
test5ListCursorOne test3 „ํ–‰‹œ „ ํƒœ Item ด 0 ฒˆงธ ž„„ ํ™•ธ
test6ListCursorTwo test4 „ํ–‰‹œ „ ํƒœ Item ด 1 ฒˆงธ ž„„ ํ™•ธ

~cpp 
	void test5ListCursorOne () {
		test3ListAdd();
		CPPUNIT_ASSERT_EQUAL(0, pDlg->m_ctlList.GetCurSel());
	}

	void test6ListCursorTwo () {
		test4ListAddMore();
		CPPUNIT_ASSERT_EQUAL(1, pDlg->m_ctlList.GetCurSel());
	}


ฝ”“œ ถ”€
~cpp 
void CGuiTestingOneDlg::OnButtonadd() 
{
	// TODO: Add your control notification handler code here
	CString str;
	m_ctlEdit.GetWindowText(str);
	m_ctlList.AddString(str);
	m_ctlList.SetCurSel(m_ctlList.GetCount()-1);
	m_bFlag = true;
}


5. edit box ˜ ‚ดšฉด ฐดํ„ถ”€ํ›„ ดˆธฐํ™” ˜Š”€ ํ™•ธ

ํ…ŒŠคํŠธ ํ†ต‹œ ˜ˆƒ˜Š” ฒฐ
test1One —ฐŠตฒธ Assert Equals. 10 == 10
test2GuiOne „ํŠด ˆŒŸฌกŒ„ ฒฝšฐ— CGuiTestingOneDlg::m_bFlag € true ƒํƒœ€ œ‹ค.
test3ListAdd Editbox — "Testing..." „ …‹ํŒ…. „ํŠ„ ˆŒ €„ •Œ Listbox ˜ item ˆ˜€ 1ฐœž„„ ํ™•ธ
. Listbox ˜ ฒซฒˆงธ item ˜ ฌธž—ดด "Testing..." ž„„ ํ™•ธ
test4ListAddMore test3 — ถ”€œ ํ˜•ํƒœ. Editbox — ‹ค‹œ "Testing2..." …‹ํŒ…ํ•˜ณ , „ํŠ„ ˆŒ €„ •Œ Listbox ˜ item ˆ˜€ 2ฐœž„„ ํ™•ธ
. Listbox ˜ ‘ฒˆงธ item ˜ ฌธž—ดด "Testing2..." ž„„ ํ™•ธ
test5ListCursorOne test3 „ํ–‰‹œ „ ํƒœ Item ด 0 ฒˆงธ ž„„ ํ™•ธ
test6ListCursorTwo test4 „ํ–‰‹œ „ ํƒœ Item ด 1 ฒˆงธ ž„„ ํ™•ธ
test7EmptyEditbox test3 „ํ–‰‹œ Editbox ˜ ŠคํŠธงด „—ˆŠ”€ ํ™•ธ

~cpp 
	void test7EmptyEditbox () {
		test3ListAdd();
		CString str;

		pDlg->m_ctlEdit.GetWindowText(str);
		CPPUNIT_ASSERT (str.IsEmpty());
	}

ฝ”“œ ถ”€
~cpp 
void CGuiTestingOneDlg::OnButtonadd() 
{
	// TODO: Add your control notification handler code here
	CString str;
	m_ctlEdit.GetWindowText(str);
	m_ctlList.AddString(str);
	m_ctlList.SetCurSel(m_ctlList.GetCount()-1);
	m_ctlEdit.SetWindowText("");
	m_bFlag = true;
}

—ฌธฐŒ€กœ ƒฐํ•ด†“€ ํ…ŒŠคํŠธ“คด  „€ ™„ฃŒ. •ž— InitInstance — จ „€ „„ ํ’€ณ , ‹ค œกœ ‹คํ–‰ํ•ดณดž.
~cpp 
BOOL CGuiTestingOneApp::InitInstance()
{
	AfxEnableControlContainer();

	CppUnit::MfcUi::TestRunner runner;
	runner.addTest (GuiTestCase::suite());
	runner.run();

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CGuiTestingOneDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
	}
	else if (nResponse == IDCANCEL)
	{
	}

	return FALSE;
}


ฌธ œ 

  • ชจ‹ฌฆฌŠค ‹คด–กœทธธ €„กœ, ํ…ŒŠคํŠธ run œกœ ‹คํ–‰ํ•  •Œ งˆ‹ค Dialog € œกŒ‹ค กŒ‹ค ํ•œ‹ค. ด— ”ฐฅธ †„˜ €—ฐ˜ ฌธ œ. -> CDialog::ShowWindow(SH_HIDE); กœ ํ•ดฒฐ €Šฅ


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:20
Processing time 0.0435 sec