Today, I started reading the example in the Test Drive Development Practical Guide (Copyup) ". I plan to write the example inside the side with C .
In the film management example in the Test-Driven Development-a Practical Guide book, the author lists 10 USER Story:
1) MOVIE LIST2) MOVIES CAN BE RENAMED3) MOVIES ARE UNIQUE4) Rattings5) Categories6) Filter on category7) Persistence8) Multiple Ratings10) Reviews
The author will develop around 10 User Story.
First, Movie List
Need to design a film list Container.
TEST 1: The size of the empty list should be 0.
Test code: void Testmovielist :: TESTEMOVIELISTSIZE () {m_pmovielist = new movielist ();
CPPUNIT_ASSERT_EQUAL (0, M_PMOVIELIST-> SIZE ());
Compilation is not passed, write product code:
Add a class MOVIELIST: class AFX_EXT_CLASS MOVIELIST (); Virtual ~ MovieList ();
PUBLIC: INT size ();
}
Size () method: int movielist :: size () {return 0;}
Compile, test, pass.
Test 2: Add a list of monograms SIZE should be 1.
Test code: Void Testmovielist :: testsizeafteraddingOne () {movie starwars; movielist oneItemlist; oneItemlist.add (& starwars);
CPPUNIT_ASSERT_EQUAL (1, OneItemlist.size ());}
Compilation is not passed, write product code. Add new class movide AFX_EXT_CLASS MOVIE {public: movie (); virtual ~ movie ();
MovieList Add to New Method Add (): Void Movielist :: Add (Movie * Pmovie) {m_nnumberofmovies = 1;}
Add new data members simultaneously to save the movie: int m_nnumberofmovies;
Today, I will write this, and the test we completed is shown in Figure 1: Figure 1