开发者

I'm looking for a good example of an integration test using Java or C# code

There are untol开发者_如何学Pythond number of unit test examples, but can you provide here, or provide a link to a good example of an integration test that isn't just a metaphor? I prefer a JUnit example, but that isn't necessarily a requirement.


Providing an example of an integration test is not soooo useful. A integration test is a test that tests multiple components together to see if they work together as expected.

Imagine you have written a lexer and a parser and would like to know if the work together properly. You might do it like this:

@Test
public void emptyContent() throws Exception {
    assertParsable("");
}

@Test
public void complexExpression() throws Exception {
    assertParsable("a + b - (a * b)");
}

@Test
public void missingClosingBrace() throws Exception {
    assertUnparsable("(a * b");
}

private void assertParsable(String input) throws Exception {
    assertFalse(parse(input).hasErrors());
}

private void assertParsable(String input) throws Exception {
    assertTrue(parse(input).hasErrors());
}

private ParseResult parse(String input) {
    return new Parser(new Lexer(input)).parse();
}

Edit:

Personally I prefer to distinguish between fast and slow tests. It doesn't matter that much (at least for me) if I do test some components in isolation or together ... what matters is, that my tests are fast. If I test to many components together the tests are not fast, of course. This depends of what you try to achieve with the tests (I use them for writing tests before/during development and as regression suite ... I don't [have to] use them to show that my implementation matches a requirement document or something like that).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜