Count the number of vowel and basic Unit Test

I write 2 methods to count the number of vowels in the string as below.

1. Returns the count of the vowel characters in the String

2. Return the number of vowels in each word in the String as a List of Integers







Looks good.

So what can I do to test the above code and make sure it works?

The idea is making a very simple Unit test with JUnit (or TestNG) framework to test these code, so I have created 2 classes: Count vowel methods and Test class as below:


This class is includes 2 methods displayVowelInString() to display the total number of vowels in the String and displayVowelInWord() to split the String into the single word and count the vowel in each word. They all returned the value to verify in the test class.



To test the above code I need to create a Unit test by using JUnit, there are 2 test methods as testVowelString() & testVowelWord()

I have changed the input value to “It should be good” and expectedVowel = 6 (all vowels in the String), expectedVowelNumber = Arrays.asList(1, 2, 1, 2).

Run the script and take a look at the results.


Now I want to check the failed status if the expected value and actual value is inconsistent by changing the expected vowels of the String “It should be good” to 9. It should be failed.

int expectedVowel = 9;

This is the basic code to get an overview, hope this help and could make you interested in this topic, keep it up and also take a look at the below links for more information.


“Unit testing, a testing technique using which individual modules are tested to determine if there are any issues by the developer himself. It is concerned with functional correctness of the standalone modules. The main aim is to isolate each unit of the system to identify, analyze and fix the defects.”

Good reads:



One thought on “Count the number of vowel and basic Unit Test”

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by Sang Bui