解决在Idea下单元测试中Scanner类不能使用的问题

大家好,我是煤油机
可爱的程序员在编写了一个单元测试的方法时,发现了一个错误

@Test
    public void test4(){
    	Scanner in = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String name = in.nextLine();
        System.out.println("请输入密码:");
        String password = in.nextLine();
        String sql = "select id from user where name = ? and password = ?";
        User user = DBUtils.commenQuerySingal(User.class, sql, name, password);
        System.out.println(user!=null?"登陆成功":"登陆失败,用户名不存在或密码错误");
    }

虽然这样写了代码,一看没有错误,但是可恶的控制台不接收我们的参数
nononono,不要着急!
下面就跟着我的步骤一步步来
解决在Idea下单元测试中Scanner类不能使用的问题_第1张图片
解决在Idea下单元测试中Scanner类不能使用的问题_第2张图片
追加这句代码

-Deditable.java.test.console=true

追加之后,重启idea
这样是不是据解决问题了呢?
来,试试看吧!

你可能感兴趣的:(intellij-idea,java)