Some of our integration tests rely on an external service during setup (a @BeforeX method) or teardown (@AfterX). Occasionally this service is flakey -- sometimes it might get re-deployed by another team in the middle of a long test run. The problem is that if one of the configuration methods fails, then any subsequent test that also has a dependency on that configuration method is skipped. We'd like it to attempt those tests anyway. Of course it is correct behavior for a given test method to be skipped if the @Before fails, we just don't want all subsequent tests also skipped.Is there a way to do this with TestNG?
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
* Failure in @Before/AfterMethod skips a single test only.
* Failure in @Before/AfterClass skips tests in that class only.
* Failure in @Before/AfterSuite skips all tests in the suite.
...
Rather than
* Failure in @Before/AfterX skips skips subsequent tests in classes
that have or inherit this configuration method.
The reason that I would prefer that TestNG not eagerly skip tests is
that I believe that I should be the one to determine whether the
environment renders my testrun useless, not TestNG. At the least, I
wish there were a way to tell TestNG to not eagerly skip tests. For
example,
@BeforeMethod(eagerlySkip = false)
public void setUp() {
throw new RuntimeException();
}
@Test testFoo() {}
@Test testBar() {}
@Test testBaz() {}
where we would see
setUp failed
testFoo skipped
setUp failed
testBar skipped
setUp failed
testBaz skipped
The problem with try/catch is that a test would never fail due to,
say, SocketException. Since I would catch it and just log, a test
would fail with some other exception, say NullPointerException, which
makes debugging harder.
> > testng-users...@googlegroups.com<testng-users%2Bunsubscribe@google groups.com>
To me, this makes more sense:
* Failure in @Before/AfterMethod skips a single test only.
* Failure in @Before/AfterClass skips tests in that class only.
* Failure in @Before/AfterSuite skips all tests in the suite.
...
Rather than
* Failure in @Before/AfterX skips skips subsequent tests in classes
that have or inherit this configuration method.
The reason that I would prefer that TestNG not eagerly skip tests is
that I believe that I should be the one to determine whether the
environment renders my testrun useless, not TestNG.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
On Apr 13, 3:07 pm, Cédric Beust ♔ <cbe...@google.com> wrote:
> On Tue, Apr 13, 2010 at 2:50 PM, Suk-Hyun Cho <choey...@gmail.com> wrote:
> > To me, this makes more sense:
>
> > * Failure in @Before/AfterMethod skips a single test only.
> > * Failure in @Before/AfterClass skips tests in that class only.
> > * Failure in @Before/AfterSuite skips all tests in the suite.
>
> This is exactly how it's implemented, are you seeing something different?
That's not the behavior I am seeing.
If I have a test base and two test classes:
public class MyTestBase
{
private static boolean didFirstTestFail = false;
@BeforeTest
public void setUp()
{
if (!didFirstTestFail)
{
didFirstTestFail = true;
throw new RuntimeException(":'(");
}
}
}
public class MyFooTest extends MyTestBase
{
@Test
public void testFoo1()
{}
@Test
public void testFoo2()
{}
}
public class MyBarTest extends MyTestBase
{
@Test
public void testBar1()
{}
@Test
public void testBar2()
{}
}
And run MyFooTest and MyBarTest in a single run, The configuration
method fails for the first time, then all the tests are skipped in
both test classes.
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
> > testng-users...@googlegroups.com<testng-users%2Bunsubscribe@google groups.com>
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
Actually, no, that's not what "strict" would do. "strict" would be used in configuration methods that are inherited by many subclasses and it would allow a failure to only apply to one subclass instead of all of them.
For discussion purposes below, I'll call this proposed feature
skipRemainingOnFailure (mostly because I like that name). I see
"skipRemainingOnFailure" as a more general-encompassing feature of
"strict". TestNG will always skip tests when a direct dependency
fails. That behavior is not under discussion and should not be
changed. For example, if @BeforeClass fails, all test methods in that
same instance will be skipped (whether inherited or not). And for an
@BeforeMethod failure, the current test method will be skipped.
However, with a @BeforeClass(skipRemainingOnFailure=false) failure
will not cause any test methods in other class instances to be skipped
(same as how you describe strict=true). In a similar fashion, a
failure in @BeforeMethod(skipRemainingOnFailure=false) will not cause
any test methods outside the currently (intended to be) executing one
to be skipped.
Thank you,
-John
On Apr 14, 11:46 am, Todd Wells <ttopwe...@gmail.com> wrote:
> skipSubsequentTestsOnFailure="false"
> skipSubsequentExecutionsOnFailure="false"
>
> or maybe skipRemaining...
>
> both seem to more accurately (if verbosely) describe the behavior. But
> ultimately the behavior is the most important part, not the attribute name.
>
> Cedric, I appreciate your responsiveness on this issue! You've built a great
> tool in TestNG and maintaining flexibility in it's functionality will allow
> it to be used in a broader set of test scenarios.
>
> On Wed, Apr 14, 2010 at 10:06 AM, Choey <choey...@gmail.com> wrote:
> > I would prefer "dontSkipOnError", or perhaps "neverSkipOnError", because to
> > me, "continueOnError" implies that the test for which the configuration
> > method was run will not be skipped but attempted to be run, which would
> > behave as if it was wrapped around in a try/catch block.
>
> > Thank you for considering this feature!
>
> > 2010/4/14 Cédric Beust ♔ <cbe...@google.com>
>
> >> Hi Todd,
>
> >> Ok, I understand what you are asking and why a try/catch is not
> >> sufficient.
>
> >> It looks like an attribute such as @BeforeMethod(*continueOnError *=
> >> true) is what you are looking for, correct? (a more accurate name would be
> >> something like "dontSkipOnError" but "don't" is a bit of an odd word to use
> >> as a Java identifier because of the apostrophe).
>
> >> --
> >> Cedric
>
> >>>> testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>
> >>>> .
> >>>> For more options, visit this group at
> >>>>http://groups.google.com/group/testng-users?hl=en.
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "testng-users" group.
> >>> To post to this group, send email to testng...@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>
> >>> .
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/testng-users?hl=en.
>
> >> --
> >> Cédric
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "testng-users" group.
> >> To post to this group, send email to testng...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/testng-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to testng...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>
@BeforeTest(dontSkipOnError = true)public void setUp() {init(); // can sometimes throw}
@BeforeTestpublic void setUp() {try {init(); // can sometimes throw} catch(MyException ex) {// ignore}}
Yes, that's exactly what I'm saying. Regardless of the ordering of the tests, once a @BeforeMethod fails, something wrong (that even you, the user, didn't anticipate) happened, and continuing to run the tests from then on will lead to garbage results. If a few test methods ran successfully before the failure happened, then these results are correct since the configurations executed properly.
Choey's example can be very easily fixed by adding a try/catch in the @BeforeTest method of the super class around the call that can possibly throw. What is so different between:@BeforeTest(dontSkipOnError = true)public void setUp() {init(); // can sometimes throw}and
@BeforeTestpublic void setUp() {try {init(); // can sometimes throw} catch(MyException ex) {// ignore}}?
This latter example seems to be much more correct since it will only ignore exceptions that you know are safe to ignore, but your test will still bomb if something unexpected happens. This seems like a much better solution.Todd writes:
For example, a common occurrence in a @Before method in a base class is to create a new account in an external service, so each test executes with a new account context. Sometimes this fails due to an issue with the external system... maybe it was taken offline for a minute while a new war was deployed. But it would be wrong to assume that because it failed once it would fail again.
If you know that account creation can fail and that it's no big deal when it does, just catch AccountCreationException and just do nothing, so same question to you: why is an attribute "dontSkipOnError" a better solution?
I thought you wanted to ignore all the configuration failures, but what you want is for the failure of that particular configuration method to be reported (and to cause skips as required) but not to cause skips later.
Now, specifying this semantics is tricky because it will vary for each configuration method.For example, for @BeforeMethod, with that flag set:bm() <--- fails
a() <--- skip or run it normally? skip
bm() <--- run normally, might succeed or fail
b() <--- depends skip if second bm() failed, otherwise run
Now, what does it mean for a @BeforeClass? The tricky case is when that method is in a base class, and therefore reused in different classes:
A#bc() <--- failsA#a() |A#b() | --- skip or run? skip all three
A#c() |
B#bc() <--- run normally, might succeed or fail
B#d |__ run normally skip all if B#bc failed, otherwise execute normally
B#e |There are three more configuration methods to go over...
Cedric, if John's team implements this, will you accept a patch? Does the proposal meet with your approval?
> ...
>
> read more »
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Typo on "continuel"?
On Jun 18, 2010, at 5:17 PM, Jek <john.m...@attachmate.com> wrote:
Ivan.-