Here are two test cases a string that consists of the

This preview shows page 10 - 12 out of 12 pages.

Here are two test cases /** = a String that consists of the first letter of each word in s. E.g. for s = “Juris Hartmanis”, the answer is “JH”. Precondition: s consists of a name in the form “first last” or “first middle last”, with one or more blanks between each pair of names. There may be blanks at the beginning and end. public String initialsOf(String s) { }
Image of page 10

Subscribe to view the full document.

11 /** A JUnit test case class. * Every method starting with the word "test" will be called when running * the test with JUnit. */ public class ChapterTester extends TestCase { /** A test method. * (Replace "X" with a name describing the test. You may write as * many "testSomething" methods in this class as you wish, and each * one will be called when testing.) */ public void testX() { } } assertEquals(x,y): test whether x equals y ; print an error message and stop the method if they are not equal. x: expected value, y: actual value. Other methods listed on page 488.
Image of page 11
12 /** Test first constructor and getter methods getTitle, getNumber, and getPrevious */ public void testFirstConstructor() { Chapter c1= new Chapter("one", 1, null); assertEquals("one”, c1.getTitle(), ); assertEquals(1, c1.getNumber()); assertEquals(null, c1.getPrevious()); } Every time you click button Test in DrJava, all methods with a name testXXX will be called. one test case /** Test Setter methods setTitle, setNumber, and setPrevious */ public void testSetters() { Chapter c1= new Chapter("one", 1, null ); c1.setTitle("new title"); c1.setNumber(18); Chapter c2= new Chapter("two", 2, null ); c1.setPrevious(c2); assertEquals("new title", c1.getTitle()); assertEquals(18, c1.getNumber()); assertEquals(c2, c1.getPrevious()); } testMethods to test getters and setters
Image of page 12
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern