我正在从事类中的Java程序工作,并且我不确定为什么或者如何失败,因为我在程序运行时得到正确的打印输出。Java的新功能 - 返回单元测试失败
这里是我的代码:
import java.util.Scanner;
public class TextAnalyzer {
// Create scanner
private static Scanner scnr = new Scanner(System.in);
// Create text string
private static String text;
public static void main(String[] args) {
System.out.println("Enter a sentence or phrase: ");
// Scan for text input
text = scnr.nextLine();
System.out.println("You entered: " + text);
// Call getNumOfCharacters
int count = getNumOfCharacters();
System.out.println();
System.out.println("Number of characters: " + count);
// Call outputWithoutWhitespace
String modifiedstring = outputWithoutWhitespace();
System.out.println("String with no whitespace: " + modifiedstring);
}
// Method outputs string without spaces
private static String outputWithoutWhitespace() {
text = text.trim().replaceAll(" ", "");
return text;
}
// Method to return number of characters
private static int getNumOfCharacters() {
return text.length();
}
}
的输出经过各级,它是在输入字符失败的数量进行单元测试,我真的只是需要一些指导新学生到Java编程。
下面是测试的打印:
我的假设是,getNumOfCharacters()
正在返回的字符数之后的空白字符已被删除,但我可能是错的。
任何帮助/指导将不胜感激。
提示:避免链接到外部网站获取更多信息。并且:只发布相关代码。含义:不是在这里粘贴主要方法,而是更好地发布失败单元测试的源代码。换句话说:请转到帮助中心,阅读“如何问”。 – GhostCat
您的方法名称错误?测试说** GetNumOfCharacters **(大写G) –
@GhostCat新用户不能内嵌图像,直到他们有10个代表。你可以也应该通过编辑来帮助他们。这里有足够的信息来看待这个问题,而且程序本身足够小以便一目了然。这是一个非常明确的问题,我们经常问人们的所有信息。 –