7

I am migrating my Junit tests from Junit v3 to Junit v4.

I was hoping to use the search and replace structurally "srs" to add an @Test annotation before all methods starting with test.* using my favorite IDE Intellij.

I just cant figura out how to do it... I can create a query that will find all methods without an annotation (there is an example bundled in Intellij) but when used to do a replace either my class gets replaced by only the method names OR nothing is found.

Maybe a regexp is easier :-)

jmiserez
  • 2,991
  • 1
  • 23
  • 34
Konstantin
  • 3,626
  • 2
  • 33
  • 45
  • I was trying to search for double checked synchronized blocks earlier today. Maybe we should file a bug report; srs does not do what we need ? – krosenvold Apr 30 '09 at 18:41
  • Yeah I guess it is a bit cryptic to the untrained, I saw one sample that was implemented with groovy. How are a mere mortal like me going to use that? – Konstantin Apr 30 '09 at 19:42
  • 1
    I've tried to use it a number of times, without success. It takes a while to figure out how to make expressions that match (even though I know quite a few RE systems), and then when applied, it deletes the target rather than substituting my replacement. A few times, I've had to look for quite a while to find all the code scattered throughout my sources that was deleted. It's more hassle than it's worth. – PanCrit May 02 '09 at 20:37

3 Answers3

1

I tried with the following SSR but I have the same problem than you :

Search template :

public class $TestCase$ extends $TestCaseClazz$ {
  public void $testMethod$();
}

Replacement template :

@Test public void $testMethod$();

And I check "This variable is target of the search" on testMethod. The preview seems ok, but IntelliJ actually delete the whole method :(

1

It is not possible, as of now, but there are requests for class members replacements.

Here is a useful link for getting started with ssr: https://www.jetbrains.com/idea/docs/ssr.pdf

tutuDajuju
  • 10,307
  • 6
  • 65
  • 88
nicity
  • 211
  • 1
  • 1
0

Open Search -> Replace in path
Set Directory to the directory where your test is placed
Set search string to: public void test.
Set replace string to: @Test\n\tpublic void test.
Check Regular Expression box.

Enjoy.

Bogdan Gusiev
  • 8,027
  • 16
  • 61
  • 81
  • Sorry not really the answer I was looking for. I was asking for the more powerful structural search. I have already done the replace using regexps. – Konstantin May 04 '09 at 11:26