-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[improvement] Add to @Test interface fields IDs and issues #2003
Comments
@juherr need consent or dialogue. |
For our own tests, we use the description for that. |
@juherr a lot of test annotations are very bad practice for autotests. For example:
|
I'm not feeling good to add new attributes to the Another option could be to support |
Your suggestion for Support I admit honestly, junit for me is a very clumsy solution, as with the flexibility they have problems in older versions, that remained even in version 5. And in my opinion, this decision should not be taken as an example. In my experience in developing autotests, TestNG is much better than junit. |
You can also add the field For example: public class ExampleTest {
@Test(description = "description", details = {"id_C2312", "issue_QA-573"})
public void test_20190106014139() { }
} |
I think a generic attribute like |
Why not do something like this Quoting for completeness. We could just have an annotation that represents a key/value pair and then enrich public @interface TableMapping {
public String dbName();
public String tableName();
} @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface column {
public TableMapping[] table();
} @column(table={
@TableMapping(dbName="dbName", tableName="tableName"),
@TableMapping(dbName="db2", tableName="table2")
})
public String userId = "userid"; |
@krmahadevan It is not possible to make a general solution that would allow the end user to add their own implementation. In your example, this is the The examples below do not work.
public @interface Test {
<A extends Details> A details();
}
public @interface DetailsImpl extends Details {
}
public @interface Test<A extends Details> {
A details();
} |
@shaburov - I wasn't talking about allowing users to inject their own types into a TestNG annotation. I was talking about enriching the I am pushing it one step above and suggesting that TestNG expose a key/value pair so that a end-user is free to add his/her own semantics. Here's a sample of what I am talking about. package org.testng.annotations;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({METHOD, TYPE})
public @interface CustomAttributes {
String name();
String value();
} Here's the modified @Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({METHOD, TYPE})
public @interface Test {
CustomAttributes[] attributes() default {};
//remaining code omitted for brevity.
} Heres the test class package com.rationaleemotions.annotations;
import java.util.Arrays;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
import org.testng.annotations.CustomAttributes;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners(SampleTestClass.class)
public class SampleTestClass implements IInvokedMethodListener {
@Test(
attributes = {
@CustomAttributes(name = "foo", value = "fooValue"),
@CustomAttributes(name = "nar", value = "barValue")
})
public void testMethod() {
System.err.println("Hello World");
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
Test test =
method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class);
System.err.println("Printing attributes");
Arrays.stream(test.attributes())
.forEach(
customAttributes -> {
System.err.println("Key = " + customAttributes.name());
System.err.println("Value = " + customAttributes.value());
});
}
} And here's the output
|
@krmahadevan I like your decision.
@juherr what do you say? In my opinion, Krishnan offered a good solution. |
LGTM 👍 |
For me, it's enough to set description value with customized format and parse it in the corresponding customized utility. |
@WengM I agree with you but Meta-annotation is a fashion alternative I'd prefer to use but need more work :) Maybe later. |
smart idea! |
As an auto tester, I want to be able to associate an autotest with a test case in the test management system and associate the test with an issue in the task tracker system.
For autotest management, it is worth adding auxiliary fields to the
@Test
interface so that the end user can manage the presentation of the results in the checklists.Fields:
String[] ids = default {};
- test case IDs. For example in testrail, kanoah or another test management system.String[] issues = default {};
- features or/and bugs in the task tracker system. For example in jira, mantis, YouTrack, etc.The text was updated successfully, but these errors were encountered: