开发者

How to test an interactive java application using cucumber and aruba

How to test an interactive java application using cucumber and aruba

I have this Cucumber/Aruba scenario:

Scenario: Simple echo
  Given I run `java -cp /bin Echo` interactively
  When I type "something\n"
  Then the output should contain "something"

To test this simple java program:

import java.util.*;
class Echo {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        System.out.println(stdin.next());
    }
}

When I run the test it fails and I get the following error:

Then the output should contain "something"
    expected "" to include "something" (RSpec::Expectations::ExpectationNotMetError)
    features/cli.feature:15:in `Then the output should contain "something"'

When I try the same test with this ruby program:

puts gets

is all green...

Am I doing something wrong here?

Do have to 开发者_开发百科use another method to read from standard input? is System.in used for the keyboard only?


A couple of things you could try:

First test that Cucumber/Aruba is picking up your System.out.println call by forcing the output to be what you expect in your test: i.e.

System.out.println("something");

If that works, then you hunch on reading standard input is correct (i have never seen someone read from standard input the way you are doing it). The answer below is how I typically see people read from standard input in Java:

How to read input with multiple lines in Java

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜