mardi 29 octobre 2019

How do I write unit test for a setter method which does not have a getter method?

I have a class which looks like this

public class Assignment {

   protected String AssName;

   public void SetAssSpec(String theSpec){

     this.AssSpec = theSpec;

   }

}

Here is my Testing class

class AssignmentTest {

   @Test
   void testSetAssSpec(){

       String assignmentName = "CSE101";
       Assignment cseAssigment = new Assignment();
       cseAssigment.SetAssSpec(String assignmentName);

       //Now what?

   }


} 

Since there is no getter method.
Another way to access the set String would be cseAssigment.AssName but the problem is the AssName is protected so I can not access it.
How would I test it? I am new to testing and Junit. So, please tell me if this even makes sense?

Aucun commentaire:

Enregistrer un commentaire