0

I have a big java project using TestNG Test annotation.

I want to add parameter timeOut=100L to all tests, that are not part of a group (defined via Test Annotation parameters). We use groups for functional/integration/etc. I want to impact only unit tests, which lack any group.

My unit tests (which are the ones I want to match) have @Test annotation by itself, or other parameters. e.g.

@Test
public void aSimpleTest() 
{
...

@Test(expectedExceptions = SomeException.class,
        expectedExceptionsMessageRegExp = "my error message",
        description = "Test will fail validation on X")
public void aSimpleTestWithAnotatedParameters() {
...

@Test(dataProvider = "testDataProvider")
public void aSimpleTestWithAnotatedParameters(Int InputVal) {
...

My first attempt was using IntelliJ Structural Find and Replace:

Search Template:

@$Annotation$($param1$ = $value1$,/*...*/ $paramN$ = $valueN$)

with Modifiers for both param1 and paramN: Text=!groups

replace with:

@$Annotation$(timeOut = 100L, $param1$ = $value1$,/*...*/ $paramN$ = $valueN$)

Which almost works!

The problem I can't solve is that it also matches things like:

@Test(description = "should not match this test, but it does", groups = "SlowIntegrationTest")

That is, Annotations with parameters other than group. The ones that have only group are not matched.

gabriel
  • 147
  • 1
  • 9

1 Answers1

0

Something like the following Structural Search & Replace should work.

Search template:

@Test($groups$ = $v$)

Modifiers:
$group$ - text=groups, count=[0,0]

Replace template:

@Test(timeOut=100L)

Or copy the following complete template and Import Template from Clipboard:

<replaceConfiguration name="Add time-out to @Test" text="@Test($groups$ = $v$)" recursive="false" type="JAVA" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="@Test(timeOut=100L)" case_sensitive="true">
  <constraint name="__context__" within="" contains="" />
  <constraint name="groups" regexp="groups" minCount="0" maxCount="0" within="" contains="" />
  <constraint name="v" within="" contains="" />
</replaceConfiguration>
Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68