-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestNG eclipse plugin doesn't show proper exception if @BeforeMethod (using ITestResult as parameter) fails #307
Comments
hi @jimpatel90, @BeforeMethod
public void setUp(ITestResult result) {
Assert.fail();
} |
Hi @missedone, In my case, setUp creates a selenium webdriver instance which is used in running test. Tests run in parallel mode at methods level. Earlier, I used ThreadLocal for driver instance to manage seperate drivers for each tests. It was working fine. But when I applied timeOut at @test level, problem started. I realized that setUp and testMethods run in different thread if timeOut is applied. Hence ThreadLocal doesn't work in this case. Then, I thought of using a Map that manages test-local-driver. For that I need unique key for each test. I used ITestResult for that because it would be unique for each test execution and I can easily use Reporter.getCurrentTestResult() to retrieve it for running test. Something like below:
DriverManager.java
Thanks |
@jimpatel90 , could you use some other ParallelMode than protected static void invokeWithTimeout(ITestNGMethod tm, Object instance,
Object[] parameterValues, ITestResult testResult, IHookable hookable)
throws InterruptedException, ThreadExecutionException {
if (ThreadUtil.isTestNGThread() && testResult.getTestContext().getCurrentXmlTest().getParallel() != XmlSuite.ParallelMode.TESTS) {
// We are already running in our own executor, don't create another one (or we will
// lose the time out of the enclosing executor).
invokeWithTimeoutWithNoExecutor(tm, instance, parameterValues, testResult, hookable);
} else {
invokeWithTimeoutWithNewExecutor(tm, instance, parameterValues, testResult, hookable);
}
} @juherr, do you have any suggestion for @jimpatel90 's case? |
Previously, I used class level parallel mode. There are certain classes that contain more test methods and hence these methods were running in single thread taking more execution time even if other threads were available. Hence I changed parallel mode to methods level to maximize use of parallel threads. Will InheritableThreadLocal work instead of ThreadLocal? It worked for one of my test(with timeOut set). I am not sure how would it behave with other tests (having DataProvider or parameters or invocationCount>1). |
The main issue is already known: testng-team/testng#914 About: @BeforeMethod
public void setUp(ITestResult result) { It is supposed to work (or fail with an appropriate message). |
@juherr , if there's no recommended approach for @jimpatel90 's use case, I think we might need to workaround this at TestNG:
|
@missedone I am not feeling it good because this state is not supposed to happen in an @jimpatel90 Is |
@juherr , Its not working without parallel too (i.e. not showing proper exception in case BTW, using InheritableThreadLocal instead of ThreadLocal worked for me. I am able to set driver instance in setUp method and retrieve same instance from test(having timeOut). Hence my problem is solved and I do't need to use ITestResult in setUp method. Thanks |
Plugin Version
6.10.0.201612030230
Steps to reproduce:
Try to run below class using eclipse (TestNG eclipse plugin) and observe report generated in eclipse.
Expected behaviour
In result, setUp should show as failed with correct exception(In this case, java.lang.AssertionError)
Actual behaviour
Test is shown as fail(instead of setUp) without giving actual exception. Also, it doesn't generate other reports (HTML and JUnit XML)
It gives following exception:
Note: If I remove ITestResult result from setUp, it works fine(gives proper exception).
Operating System
Windows
The text was updated successfully, but these errors were encountered: