Skip to content

Disallow using @BeforeTest and @AfterTest #17680

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

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .mvn/modernizer/violations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,16 @@
<version>1.8</version>
<comment>Use io.airlift.slice.SizeOf.instanceSize</comment>
</violation>

<violation>
<name>org/testng/annotations/BeforeTest</name>
<version>1.8</version>
<comment>Prefer org.testng.annotations.BeforeClass</comment>
</violation>

<violation>
<name>org/testng/annotations/AfterTest</name>
<version>1.8</version>
<comment>Prefer org.testng.annotations.AfterClass</comment>
</violation>
</modernizer>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
Expand All @@ -42,7 +41,6 @@ public class ReportAfterMethodNotAlwaysRun
implements IClassListener
{
private static final Set<AnnotationPredicate<?>> VIOLATIONS = ImmutableSet.of(
new AnnotationPredicate<>(AfterTest.class, not(AfterTest::alwaysRun)),
new AnnotationPredicate<>(AfterMethod.class, not(AfterMethod::alwaysRun)),
new AnnotationPredicate<>(AfterClass.class, not(AfterClass::alwaysRun)),
new AnnotationPredicate<>(AfterSuite.class, not(AfterSuite::alwaysRun)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -75,10 +74,6 @@ public static Object[][] incorrectCases()
SuiteNotAlwaysRun.class,
SuiteNotAlwaysRun.class.getMethod("afterSuite").toString(),
},
{
TestNotAlwaysRun.class,
TestNotAlwaysRun.class.getMethod("afterTest").toString(),
},
{
AllNotAlwaysRunTwice.class,
AllNotAlwaysRunTwice.class.getMethod("afterClass1").toString(),
Expand All @@ -89,8 +84,6 @@ public static Object[][] incorrectCases()
AllNotAlwaysRunTwice.class.getMethod("afterMethod2").toString(),
AllNotAlwaysRunTwice.class.getMethod("afterSuite1").toString(),
AllNotAlwaysRunTwice.class.getMethod("afterSuite2").toString(),
AllNotAlwaysRunTwice.class.getMethod("afterTest1").toString(),
AllNotAlwaysRunTwice.class.getMethod("afterTest2").toString(),
},
{
SubClassWithBaseNotAlwaysRunNoOverride.class,
Expand Down Expand Up @@ -137,9 +130,6 @@ public void afterMethod() {}

@AfterSuite(alwaysRun = true)
public void afterSuite() {}

@AfterTest(alwaysRun = true)
public void afterTest() {}
}

private static class ClassNotAlwaysRun
Expand All @@ -155,9 +145,6 @@ public void afterMethod() {}

@AfterSuite(alwaysRun = true)
public void afterSuite() {}

@AfterTest(alwaysRun = true)
public void afterTest() {}
}

private static class GroupNotAlwaysRun
Expand All @@ -173,9 +160,6 @@ public void afterMethod() {}

@AfterSuite(alwaysRun = true)
public void afterSuite() {}

@AfterTest(alwaysRun = true)
public void afterTest() {}
}

private static class MethodNotAlwaysRun
Expand All @@ -191,9 +175,6 @@ public void afterMethod() {}

@AfterSuite(alwaysRun = true)
public void afterSuite() {}

@AfterTest(alwaysRun = true)
public void afterTest() {}
}

private static class SuiteNotAlwaysRun
Expand All @@ -209,27 +190,6 @@ public void afterMethod() {}

@AfterSuite
public void afterSuite() {}

@AfterTest(alwaysRun = true)
public void afterTest() {}
}

private static class TestNotAlwaysRun
{
@AfterClass(alwaysRun = true)
public void afterClass() {}

@AfterGroups(alwaysRun = true)
public void afterGroup() {}

@AfterMethod(alwaysRun = true)
public void afterMethod() {}

@AfterSuite(alwaysRun = true)
public void afterSuite() {}

@AfterTest
public void afterTest() {}
}

private static class AllNotAlwaysRunTwice
Expand Down Expand Up @@ -257,12 +217,6 @@ public void afterSuite1() {}

@AfterSuite
public void afterSuite2() {}

@AfterTest
public void afterTest1() {}

@AfterTest
public void afterTest2() {}
}

private abstract static class BaseClassAlwaysRun
Expand Down