system.in上的junit5测试扫描仪

问题描述 投票:0回答:1

如何为以下方法使用junit5创建测试方法?

  public static String readFromDBOrFile() {
String fileOrDB;
do {
  Scanner scanner = new Scanner(System.in);
  System.out.print("Select between reading from 'file' or 'DB': ");
  String line = scanner.nextLine().toUpperCase().trim();
  fileOrDB = !line.equals("FILE") && !line.equals("DB") ? null : line;
  if(fileOrDB == null) System.out.println("Not a valid choice. Try again");
} while(fileOrDB == null);
System.out.println("Reading from : '" + fileOrDB + "'");
return fileOrDB;

}

java java.util.scanner junit5
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.