Question
JUnit Test Case code: Modify your word search array program (Homework program #1) to create a test class for it using the JUnit tool. When
JUnit Test Case code: Modify your word search array program (Homework program #1) to create a test class for it using the JUnit tool. When you run the test class using JUnit, it should indicate a pass or fail for each method. If you like, create a test suite to test one or more test classes, but I will only require that you create at least one test class. Note that you will need to modify your original program; the JUnit tests do not contain main methods. They contain the class being tested, and the JUnit test class.
import java.util.Scanner; import javax.swing.JOptionPane;
//hw1 public class WordArray { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("How many words are in the list? "); int listSize = scanner.nextInt(); String[] wordList = new String[listSize]; for (int i = 0; i < wordList.length; i++) { System.out.print("What is word number " + (i + 1)); String newWord = scanner.next(); wordList[i] = newWord; } System.out.print("Type a word to search for: "); String userInput = scanner.next(); // Description of the program JOptionPane.showMessageDialog(null, " This program calls a method to search an array for the word " + userInput); System.out .println(" This program calls a method to search an array for the word " + userInput); String in = "userInput"; int wordCounter = 0; for (int i = 0; i < wordList.length; i++) { if (wordList[i].contains(userInput)) { wordCounter = wordCounter; JOptionPane.showMessageDialog(null, "Word found: " + wordList[i]); } } JOptionPane.showMessageDialog(null, " The word " + userInput + " appears " + wordCounter + " times"); System.out.print("The word " + userInput + " appears " + wordCounter + " times"); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started