jeudi 29 octobre 2015

JUnit Test Method for a method that returns a string

Below is my Cylinder class, and then the JUnit test that I am trying to use to test the getLabel method I wrote. I am having trouble understanding how to properly form a test method when I am testing for a string that the user will input.

public class Cylinder {
   private String label = "";
   private double radius;
   private double height;
   private static int count = 0;

   /**
   * Creates a new Cylinder object with a given label, radius, and height.
   * 
   * @param label2 The name of the cylinder returned as a String.
   * @param radius2 The radius of the cylinder as a double.
   * @param height2 The height of the cylinder as a double.
   */
   public Cylinder(String label2, double radius2, double height2, int count2) {
      setLabel(label2);
      setRadius(radius2);
      setHeight(height2);
      setCount(count2);
   }
   /**
   * This method is respondible for getting the label from the user 
   * and returns a string representation of the label.
   *
   * @return String representation of the label of the Cylinder.
   */
   public String getLabel() {
      return label;
   }

Below is my JUnit test class, which I am using to create a test for each method in my Cylinder class.

public class CylinderTest {

   private String label = "";
   private double radius;
   private double height;

   /*
   *
   */
   @Test public void labelTest() {
      Cylinder c1 = new Cylinder("", radius, height);

      String result = c1.getLabel(label);

      Assert.assertEquals(" ", label);

Aucun commentaire:

Enregistrer un commentaire