Skip to content
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

Dynamically setting @TmsLink, @DisplayName & @Issue with DataProvider data #156

Closed
1 of 2 tasks
symonk opened this issue Oct 25, 2017 · 8 comments
Closed
1 of 2 tasks

Comments

@symonk
Copy link

symonk commented Oct 25, 2017

I'm submitting a ...

  • bug report
  • feature request
    template.

What is the current behavior?

I cannot seem to figure out a way in order to set the Issue, TmsLink and display name programmatically from the @test method, I have tried overriding the value(s) at runtime but with no success, my report does not seem to include the data

What is the motivation / use case for changing the behavior?

When using the junit @dataProvider annotation and passing data from a 2D array, we can then set our Issue/TmsLink/DisplayNames in the array test data and the report would reflect such data.

My sincerest apologies if this is possible to do already, I am struggling to find a way to make it work effectively

Allure version 2.2.0
Test framework junit 4.12
Allure adaptor allure-junit4@2.0-BETA13
Generate report using allure-maven@2.19

Other information

When annotating the method with the @issue("foo"), all tests of the data provider will be set with this IssueId

Note: Sorry i logged this issue in the wrong project, please close close the issue here:
allure-framework/allure2#645

@symonk
Copy link
Author

symonk commented Oct 25, 2017

I am able to achieve this by implementing Issue and overriding the value() at runtime, is there a simpler more readable/friendly means of doing so? if not this is something I feel has real benefit in adding

@symonk
Copy link
Author

symonk commented Oct 26, 2017

we can implement Issue/DisplayName/TmsLink in our own class, then using the java reflection API check for the test method at runtime and override the values for these annotations but we must set them as blank on the test method, my solution works but its very hacky and really unclean, is there a better way guys?

  @UseDataProvider("saveCourseData")
    @DisplayName("")
    @Issue("")
    @TmsLink("")
    	Method m = SaveCourse.class.getDeclaredMethod("savecourse_scenarios_return_appropriate_responses", SeverityLevel.class, 
        		String.class, String.class, String.class
                , int.class, String.class, String.class, int.class, int.class, boolean.class, boolean.class, int.class,
                String.class);
        Issue i = m.getAnnotation(Issue.class);
        DynamicIssue di = new DynamicIssue(issueId);
        AnnotationHelper.changeAnnotationValue(i, "value", di.value());

@Juvat
Copy link

Juvat commented Aug 13, 2018

Any update on this? I'd also like to see that feature. In my current project I sometimes have up to 20 parametrized tests served by one test method and it's difficult to keep track of all @TmsLinks. Solution above if fine but it would require a lot of changes in existing tests.

@baev
Copy link
Member

baev commented Aug 13, 2018

@Juvat
Copy link

Juvat commented Aug 13, 2018

@baev that will do the trick. Thanks a lot!

@baev baev closed this as completed Oct 31, 2018
@dhruvvinayak
Copy link

@Juvat, can you please share the code snippet you implemented using Allure.getLifecycle() API?

@GregoryGum
Copy link

GregoryGum commented Oct 24, 2020

I am using following code to dynamicly change DisplayName at run time:
AllureLifecycle oLifecycle = Allure.getLifecycle();
oLifecycle.updateTestCase(testResult -> testResult.setName("My DisplayName"));

@vlad230
Copy link

vlad230 commented Dec 15, 2022

I'm struggling to get it work but it's not working for me.

I am using this approach: https://www.swtestacademy.com/change-test-name-testng-dataprovider/

Instead of the Extent report part I'm using this to updated the allure report test case name but it's not working with the latest Allure version 2.20.1:

public class TestListener extends ApiBaseTest implements ITestListener {

    @Override
    public void onTestStart(ITestResult result) {
        log.info("Executing test method: {} from test class: {}", result.getName(), result.getTestClass().getName());

        //update test method name in Allure report
        Allure.getLifecycle().updateTestCase(testResult -> testResult.setName(result.getName()));
    }
.....

I see the method name change while executing in IntelliJ, in the console output, the instance name is changed in the testng-results.xml but does not change the Displayed Name in the Allure report (I still see the default method name) and get these errors:

Warning: [org.testng.ITest] implementation on class [api.tests.X] returned null. Defaulting to method name
[main] ERROR io.qameta.allure.AllureLifecycle - Could not update test case: test case with uuid 4df36479-0c30-408c-92f7-86d65686a038 not found

Any ideas @baev, @Juvat, @GregoryGum ? What am I doing wrong?

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

No branches or pull requests

6 participants