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?
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).
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.
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!"
I think that is possible, but perhaps the "JUnit test method without any assertions" inspection would be easier?
Bas
Omair-Inam Abdul-Matin wrote:
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
Bas Leijdekkers wrote:
Probably...
Would it be possible to automatically repair all of the violating test
classes?
Omair
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
Dave Griffith wrote:
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.
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:
>> 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!"
Will be possible in nearest future.
Omair-Inam Abdul-Matin wrote:
--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"