Structural replace: Finding JUnit tests with no assert stmts

Would someone know if it is possible to find JUnit tests with no assert
statements using a structural search?

Omair

7 comments
Comment actions Permalink

I think that is possible, but perhaps the "JUnit test method without any assertions" inspection would be easier?

Bas

0
Comment actions Permalink

Omair-Inam Abdul-Matin wrote:

Would someone know if it is possible to find JUnit tests with no assert
statements using a structural search?

Omair

I can successfully use SS to find JUnit class that have no statements or
just comments.. but if I use SSR to try to replace any instances, my
search string must be:

public class $TestCase$ extends $TestCaseClazz$ {
public void $testMethod$ () {
$stmt$; // this occurs 0 times
};
}

and if I use the replace string:

public class $TestCase$ extends $TestCaseClazz$ {
}

all the methods in the class are removed, not just the test class...
Anyone have any ideas?

Thanks,

Omair

0
Comment actions Permalink

Bas Leijdekkers wrote:

I think that is possible, but perhaps the "JUnit test method without any assertions" inspection would be easier?

Bas

Probably...

Would it be possible to automatically repair all of the violating test
classes?

Omair

0
Comment actions Permalink

What would the fix be? The only thing I can think of that makes sense would be to add a call to fail() at the end of the method. I actually quite like the sound of that, particularly since the call to fail() would prevent the inspection from firing (as it counts as an assert).

--Dave Griffith

0
Comment actions Permalink

Dave Griffith wrote:

What would the fix be? The only thing I can think of that makes sense would be to add a call to fail() at the end of the method. I actually quite like the sound of that, particularly since the call to fail() would prevent the inspection from firing (as it counts as an assert).

--Dave Griffith

I remove the tests... I can remove the tests if I put a $stmt$; before
and after and set them to be occurring between 0 and 100000 times...

This uncovered a bug in SSR which I have filed with JIRA.

0
Comment actions Permalink

Hi,

You'd need to have variable ($RemainingMethodsClassesFields$ occurs 0
... maxvalue in code below) that matches/contains remaining class
content (fields, methods or inner classes):

Search for:
public class $TestCase$ extends $TestCaseClazz$ {
public void $testMethod$ () {
$stmt$; // this occurs 0 times
};
$RemainingMethodsClassesFields$
}

public class $TestCase$ extends $TestCaseClazz$ {
$RemainingMethodsClassesFields$
}

Omair-Inam Abdul-Matin wrote:

Omair-Inam Abdul-Matin wrote:

>> Would someone know if it is possible to find JUnit tests with no
>> assert statements using a structural search?
>>
>> Omair


I can successfully use SS to find JUnit class that have no statements or
just comments.. but if I use SSR to try to replace any instances, my
search string must be:

public class $TestCase$ extends $TestCaseClazz$ {
public void $testMethod$ () {
$stmt$; // this occurs 0 times
};
}

and if I use the replace string:

public class $TestCase$ extends $TestCaseClazz$ {
}

all the methods in the class are removed, not just the test class...
Anyone have any ideas?

Thanks,

Omair



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Will be possible in nearest future.

Omair-Inam Abdul-Matin wrote:

Would someone know if it is possible to find JUnit tests with no assert
statements using a structural search?

Omair



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Please sign in to leave a comment.