Skip to content

Fix stack trace output for TestNG failures#1286

Merged
jdneo merged 17 commits intomicrosoft:mainfrom
Kropie:main
Aug 28, 2021
Merged

Fix stack trace output for TestNG failures#1286
jdneo merged 17 commits intomicrosoft:mainfrom
Kropie:main

Conversation

@Kropie
Copy link
Copy Markdown
Contributor

@Kropie Kropie commented Aug 18, 2021

This will fixes #1260.

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 18, 2021

Thank you for your contribution, I'll take a look this week

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 18, 2021

I tested the PR locally, but seems it's still not showing the errors according to the steps in #1260? Did I miss anything?

BTW, the refactoring looks good.

Comment thread src/runners/testngRunner/TestNGRunnerResultAnalyzer.ts Outdated
@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 19, 2021

@Kropie Would you like to update your PR?

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 20, 2021

@jdneo I will update my pull request tomorrow morning with the recommendations that you provided above. Thanks for your help on this!

…lure analysis logic was refactored to generate clearer test report info when "peeking" a test failure.
@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 20, 2021

@jdneo I've updated this PR to address the comments that you have above. Additionally I cleaned up the failure processing logic to clean up the "peek" view for test failures.

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 20, 2021

This is the result of the latest commit when running a failing test.
image

@Kropie Kropie requested a review from jdneo August 21, 2021 02:59
@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 21, 2021

@Kropie The PR looks good now. the common logic is shared with this refactoring. But seems that it does not fix #1260, did I miss anything?

#1260 is a bug that when the suite is failed to run, nothing shows in UI except for the output channel. You can try download the project attached in #1260, and click run all.

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 21, 2021

@jdneo I may have missed a portion of the problem statement for #1260, but this does solve the formatting issues that were previously present when you would print out the results from the "peek error" screen. Additionally this resolves the stack trace issues in the preview.

Should the stack trace also be printing out on the debug console?

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 21, 2021

After looking running with the code linked in the pull request, this PR will resolve the formatting issues. That being said, if an exception is thrown while the tests are running all subsequent tests will not be able to run.

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 21, 2021

Finally figured out what I believe is the root of the problem. The tests in the example project use groups, but the test runner currently does not support selenium groups. I just pushed another commit that logs the error clearly to the user.

I think with the additional logging we have addressed the original issue in #1260 and an additional ticket should be written for adding TestNG group support to the java test runner extension.

Now when you run the tests you will see the following error message in the debug console.

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 21, 2021

This is an example of an error that is logged to the debug console to make things clearer to the user
image

@jdneo jdneo added this to the 0.32.0 milestone Aug 22, 2021
@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 22, 2021

The screenshot looks good. I'll take a deep look tomorrow.

I think with the additional logging we have addressed the original issue in #1260 and an additional ticket should be written for adding TestNG group support to the java test runner extension.

Yes as you said, the current implementation of the TestNG runner has a lot of limitations. I'm hoping to migrate to the TestNG's official runner: https://github.com/testng-team/testng-remote, but so far does not have time to do this. 😥

Comment thread src/runners/testngRunner/TestNGRunnerResultAnalyzer.ts Outdated
@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 24, 2021

@jdneo Other than merging in the latest changes in from master is there anything else that needs to be done to merge and close this PR?

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 24, 2021

As I commented above, the refactor introduced a regression for the stacktrace of the TestNG cases. See: #1286 (comment)

That needs to be resolved before merging.

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 24, 2021

I’ll resolve that tomorrow, thanks!

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 25, 2021

As I commented above, the refactor introduced a regression for the stacktrace of the TestNG cases. See: #1286 (comment)

That needs to be resolved before merging.

Okay, @jdneo I believe I've resolved the issue with the stack trace that is being presented in the error message. I'm not positive what exactly it is supposed to look like but I've come up with what I believe is the right information.

JUnit

image

TestNG

image

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 25, 2021

I just tried with the new commit but I'm afraid it introduced new regression.

Previously, For JUnit, we can show the assertion failure via the diff view:
WeChat Screenshot_20210825094934

But now, it becomes to a plain text with a single line stack trace:
WeChat Screenshot_20210825094856

I guess you thought it a little bit complicated, base on this commit, you can simply make the following change to make it work:

In TestNGRunnerResultAnalyzer, in the else if (outputData.name === TEST_FAIL) block :

...
if (outputData.attributes.trace) {
    ...
    for (const line of outputData.attributes.trace.split(/\r?\n/)) {
        this.processStackTrace(line, markdownTrace, undefined, this.currentItem, this.projectName);
    }

    const testMessage: TestMessage = new TestMessage(markdownTrace);
    if (item.uri && item.range) {
        testMessage.location = new Location(item.uri, item.range);
    }
    testMessages.push(testMessage);
}
const duration: number = Number.parseInt(outputData.attributes.duration, 10);
setTestState(this.testContext.testRun, item, this.currentTestState, testMessages, duration);
...

Just to provide more background information. We have two different test message:

  1. The stack trace, which is the one you are dealing with
  2. The assertion failure(expected ... but actual ...) showing with a diff view. This is the third argument of your extracted function processStackTrace. This is optional, in TestNG, we didn't support it, so you can just pass undefined to it.

meanwhile, it's great that you also extracted the code to set the location of the test messages, but that can be addressed in another PR (to avoid this one become bigger and bigger endlessly).

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 25, 2021

I just tried with the new commit but I'm afraid it introduced new regression.

Previously, For JUnit, we can show the assertion failure via the diff view:
WeChat Screenshot_20210825094934

But now, it becomes to a plain text with a single line stack trace:
WeChat Screenshot_20210825094856

I guess you thought it a little bit complicated, base on this commit, you can simply make the following change to make it work:

In TestNGRunnerResultAnalyzer, in the else if (outputData.name === TEST_FAIL) block :

...
if (outputData.attributes.trace) {
    ...
    for (const line of outputData.attributes.trace.split(/\r?\n/)) {
        this.processStackTrace(line, markdownTrace, undefined, this.currentItem, this.projectName);
    }

    const testMessage: TestMessage = new TestMessage(markdownTrace);
    if (item.uri && item.range) {
        testMessage.location = new Location(item.uri, item.range);
    }
    testMessages.push(testMessage);
}
const duration: number = Number.parseInt(outputData.attributes.duration, 10);
setTestState(this.testContext.testRun, item, this.currentTestState, testMessages, duration);
...

Just to provide more background information. We have two different test message:

  1. The stack trace, which is the one you are dealing with
  2. The assertion failure(expected ... but actual ...) showing with a diff view. This is the third argument of your extracted function processStackTrace. This is optional, in TestNG, we didn't support it, so you can just pass undefined to it.

meanwhile, it's great that you also extracted the code to set the location of the test messages, but that can be addressed in another PR (to avoid this one become bigger and bigger endlessly).

First, thanks for your patience!
Second, I was able to resolve the regression with the "Expected ... but actual ... logic" that you referenced above.

I pushed the update out based on my last commit because the delta was rather small. Let me know if you would still rather have me do the code update that you referenced above on the previous commit.

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 25, 2021

Thanks for the quite response! Personally, I would prefer to reset to the commit I mentioned and append commit based on that. (To make the total change as simple as possible). We can definitely address other issues by several PRs separately.

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 25, 2021

Thanks for the quite response! Personally, I would prefer to reset to the commit I mentioned and append commit based on that. (To make the total change as simple as possible). We can definitely address other issues by several PRs separately.

Just tried to make the modification to the commit referenced above, but that has issues that are addressed by my latest commit. Specifically if you have a stack trace with multiple elements in it and you have a failure message instead of a "expected .. but actual ..." message you will only see the first element on the stack at the time of the failure.

Additionally for TestNG tests you only ever get the first element on the stack at the time of failure.
Also, for help visualizing the problem:

Limited Stack Trace (Update of referenced commit)

image

Full Stack Trace (Current latest commit in this PR)

image

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 25, 2021

That being said I am okay with updating that previous commit and just creating another PR if that is your preference.

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 25, 2021

I prefer to resolve them separately in different PRs. So this PR is aiming to resolve #1260 & #1291.

I believe the problem you mentioned is similar to #1266, and we can for sure resolve that problem in another PR.

Please correct me if I misunderstand

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 25, 2021

That works for me. I'll have the pull request updated tomorrow

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 26, 2021

@jdneo reverted back to the previous commit and made the suggested change to the TestNG analyzer.

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 26, 2021

Seems there are lint errors:

ERROR: /home/runner/work/vscode-java-test/vscode-java-test/src/runners/testngRunner/TestNGRunnerResultAnalyzer.ts:90:1 - trailing whitespace

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 26, 2021

Seems there are lint errors:

ERROR: /home/runner/work/vscode-java-test/vscode-java-test/src/runners/testngRunner/TestNGRunnerResultAnalyzer.ts:90:1 - trailing whitespace

Just resolved them

@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 26, 2021

Thank you! I'll take a look later today/tomorrow

Comment thread src/runners/testngRunner/TestNGRunnerResultAnalyzer.ts Outdated
@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 26, 2021

Overall good, but just one small peace, please see my comment.

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 27, 2021

@jdneo is there anything else for this PR I need to do? (Reference response in commit review)

@jdneo jdneo merged commit 1bc3c5b into microsoft:main Aug 28, 2021
@jdneo
Copy link
Copy Markdown
Member

jdneo commented Aug 28, 2021

@Kropie, looks pretty good! Thank you for the nice job!

@Kropie
Copy link
Copy Markdown
Contributor Author

Kropie commented Aug 28, 2021

@Kropie, looks pretty good! Thank you for the nice job!

Thanks for the guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error message is not clear when run TestNG project

2 participants