-
Notifications
You must be signed in to change notification settings - Fork 6
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
Test annotated with @Test(enabled=false)
and @Ignore
should be reported as skipped
#3
Comments
I briefly looked into this. It seems methods with |
@juherr @krmahadevan Is that difference on purpose or accidental? |
About reporting, I don't know what is the best option but not reported because disabled looks legit. |
When I'm in an implementation of @krmahadevan Do you know? |
@marcphilipp - That is why The below example should demonstrate the behavior. import org.testng.Assert;
import org.testng.IClassListener;
import org.testng.ITestClass;
import org.testng.ITestNGMethod;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
public class LocalTestRunner {
@Test(dataProvider = "testData")
public void demonstrateBehavior(Class<?> clazz, boolean isNull) {
TestNG testng = new TestNG();
testng.setTestClasses(new Class[]{clazz});
testng.setVerbose(2);
LocalClassListener listener = new LocalClassListener();
testng.addListener(listener);
testng.run();
Assert.assertEquals(listener.getTestMethods() == null, isNull);
}
@DataProvider(name = "testData")
public Object[][] getData() {
return new Object[][]{
{TestClassWithAllTestsExplicitlyDisabled.class, true},
{TestClassUsingIgnoreToDisableAllMethods.class, true},
{TestClassWithMixedCombinations.class, false}
};
}
public static class TestClassWithAllTestsExplicitlyDisabled {
@Test(enabled = false)
public void test1() {
}
@Test(enabled = false)
public void test2() {
}
}
@Ignore
public static class TestClassUsingIgnoreToDisableAllMethods {
@Test
public void test1() {
}
@Test
public void test2() {
}
}
public static class TestClassWithMixedCombinations {
@Test
public void runnableTest() {
}
@Test(enabled = false)
public void disabledTest() {
}
@Ignore
@Test
public void ignoredTest() {
}
}
public static class LocalClassListener implements IClassListener {
private ITestNGMethod[] testMethods;
@Override
public void onBeforeClass(ITestClass testClass) {
testMethods = testClass.getTestMethods();
}
public ITestNGMethod[] getTestMethods() {
return testMethods;
}
}
} |
All the So, it sounds like an issue when listeners are involved. We should investigate and fix it on TestNG side. |
@juherr - Currently Testng is behaving the same way when
That was what my sample was trying to show. Since in the second case ( |
@krmahadevan Thanks for the sample! Given the status quo, I don't see how the engine could reliably report tests annotated with |
@krmahadevan Right! I didn't realize your sample already highlights similar behavior between
but it looks like some not-expected differences exist.
@marcphilipp Like https://github.com/cbeust/testng/blob/master/testng-core/src/main/java/org/testng/internal/annotations/IgnoreListener.java I think you can collect all methods into an |
Thanks for the suggestion! That could be done but it would mean somewhat duplicating TestNG's internals (i.e. what it considers a test method etc.) since the code currently gets most of its info from |
@krmahadevan @marcphilipp |
@marcphilipp - Can you please tell me if this is just a reporting requirement ? If yes, then can we consider building something on top of the |
Yes, this is for reporting. Other testing frameworks such as JUnit and Spock report skipped tests including a reason so there's at least some indication that not all tests were executed and why. If you're interested, we can set up a call and I can walk you through the current engine implementation so you might get a better idea what would be necessary. |
@marcphilipp - Sure. I am ok with a call this saturday ( July 17). |
@krmahadevan @juherr I've sent you a meeting invite for tomorrow via email. Please let me know if that works for you. |
@marcphilipp - I have accepted the invite. |
I can't be present but @krmahadevan knows everything :) |
@marcphilipp - In the last call we discussed the below two discrepancies for which I was to get back to you.
|
On (2), Once my above mentioned PR gets merged, then you should be able to use the The below sample demonstrates this (For this sample to work, the above mentioned PR has to be merged) import java.util.List;
import java.util.stream.Collectors;
import org.assertj.core.api.Assertions;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.TestNG;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
public class ExampleClass {
@Test
public void sampleTestCase() {
TestNG testng = new TestNG();
testng.setTestClasses(new Class[]{ExampleTest.class});
ExampleListener l = new ExampleListener();
testng.addListener(l);
testng.run();
String[] expected = new String[] {"disabledTest", "ignoredTest"};
Assertions.assertThat(l.getMethods()).containsExactlyInAnyOrder(expected);
}
public static class ExampleTest {
@Test(enabled = false)
public void disabledTest() {
}
@Test
@Ignore
public void ignoredTest() {}
}
public static class ExampleListener implements ITestListener {
private List<String> methods;
public List<String> getMethods() {
return methods;
}
@Override
public void onStart(ITestContext context) {
methods = context.getExcludedMethods().stream()
.map(each -> each.getConstructorOrMethod().getMethod().getName())
.collect(Collectors.toList());
}
}
} |
Thanks for the update! Would |
@krmahadevan I did a quick check and it seems only the mixed method use case is supported this way. In that sense |
@marcphilipp - I didnt try out the scenario you mentioned. Will check it out and get back. Please give me sometime. |
Here's what I have so far: The example test classes that I have import org.testng.annotations.Test;
@Test(enabled = false)
public class ClassWithOnlyDisabledTestsAtClassLevel {
public void disabledTest() {}
public void ignoredTest() {}
} import org.testng.annotations.Test;
public class ClassWithOnlyDisabledTestsAtMethodLevel {
@Test(enabled = false)
public void disabledTest() {}
@Test(enabled = false)
public void ignoredTest() {}
} import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
@Test
@Ignore
public class ClassWithOnlyIgnoredTestsAtClassLevel {
public void disabledTest() {}
public void ignoredTest() {}
} import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
public class ClassWithOnlyIgnoredTestsAtMethodLevel {
@Test
@Ignore
public void disabledTest() {}
@Test
@Ignore
public void ignoredTest() {}
} The listener that I am using import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.testng.IClassListener;
import org.testng.ITestClass;
import org.testng.ITestContext;
import org.testng.ITestListener;
public class ExampleListener implements IClassListener, ITestListener {
private List<String> methods;
public List<String> getMethods() {
return methods;
}
@Override
public void onBeforeClass(ITestClass testClass) {
methods = Arrays.stream(testClass.getTestMethods())
.map(each -> each.getConstructorOrMethod().getMethod().getName())
.collect(Collectors.toList());
}
@Override
public void onFinish(ITestContext context) {
List<String> excluded = context.getExcludedMethods().stream()
.map(each -> each.getConstructorOrMethod().getMethod().getName())
.collect(Collectors.toList());
if (methods == null || methods.isEmpty()) {
methods = excluded;
} else {
methods.addAll(excluded);
}
}
} And here's the test class that works for all the above 4 combinations. import org.assertj.core.api.Assertions;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class ExampleClass {
@Test(dataProvider = "getData")
public void sampleTestCase(Class<?> cls) {
TestNG testng = new TestNG();
testng.setTestClasses(new Class[]{cls});
ExampleListener l = new ExampleListener();
testng.addListener(l);
testng.run();
String[] expected = new String[]{"disabledTest", "ignoredTest"};
Assertions.assertThat(l.getMethods()).containsExactlyInAnyOrder(expected);
}
@DataProvider
public Object[][] getData() {
return new Object[][]{
{ClassWithOnlyDisabledTestsAtClassLevel.class},
{ClassWithOnlyDisabledTestsAtMethodLevel.class},
{ClassWithOnlyIgnoredTestsAtClassLevel.class},
{ClassWithOnlyIgnoredTestsAtMethodLevel.class}
};
}
} |
@marcphilipp - Does the above shared listener example suffice for all the use cases ? |
Thanks for the example! I think that should be sufficient to track all disabled/ignored tests. |
Being able to see in the report that tests were skipped because they were ignored or disabled would also be useful for us. It doesn't matter for us if the they are reported as skipped versus a new category like ignored or disabled; what is important is that we know that some of our tests were not run. |
Currently such tests are not reported at all.
Related issue: gradle/gradle#1403
The text was updated successfully, but these errors were encountered: