lundi 3 août 2015

How to write a unit testing for the XXoccurences program

I am very new to programming and I have written the following code for taking Input from user and counting the number of 'xx' appearances in the same. The code is as follows. import java.util.Scanner; public class xxoccurances {

      public static void main(String[] args) {


          Scanner in = new Scanner(System.in);
          System.out.print("Enter a string: ");
         String s= in.nextLine();

         xxoccurances a = new xxoccurances();

                System.out.println( a.numberofxx(s) );

      }

      int numberofxx(String str) {
        int b = 0;

        for(int i = 0; i < str.length() - 1; i++){
          if(str.substring(i, i+2).equals("xx")){
            b = b + 1;
          }
        }

        return b;
      }

    }

I need to write a Unit test for the same, I have read about Junit Testing but I am quite unsure how to implement it in this program. Please Help..

Aucun commentaire:

Enregistrer un commentaire