| Issue 32: | Patch provided: Cleanup TestNG, fix converter tool to use non-deprecated annotations, and keep auto-converted tests isolated by groups | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Attached is a patch that addresses the following details: What steps will reproduce the problem? 1. Open an existing JUnit test case. 2. Hit Ctrl+1 (Quick Fix), and when offered choice of conversion, choose Java 5 annotations. What is the expected output? What do you see instead? Expected output is the testXXX methods to be wrapped in @Test, setUp wrapped in @BeforeMethod, tearDown wrapped in @AfterMethod, and suite wrapped in @Factory. To make test cases stay isolated (as define in JUnit), each TestClass should define its own group. Actual output are deprecated annotations. In the spirit of "funtional" vs. "broken" vs. "checkin" style (as I read on the site's documentation), it would be useful is this grouping was prefixed "functional". For example, in test class TestMyPOJOs, it would be useful to markup TestMyPOJOs.setUp with @BeforeMethod(groups="functional.TestMyPOJOs"), each testXXX method with @Test(groups="functional.TestMyPOJOs"), and so forth. This keeps setUp from another auto-converted TestSomeOtherPOJOs, from interfering with this test case. This makes it easy to write a simple, run-everything-that-was-converted, by manually building a testng.xml, with groups="functional.*" pattern. What version of the product are you using? On what operating system? TestNG 5.8.0.2, TestNG Eclipse plugin 5.8.0.5b, Windows XP, Eclipse 3.3 Please provide any additional information below. Eclipse spots a lot of unused variables. I deleted the unused variables, and also unused methods, to reduce the number of warnings. I am also getting reports of deprecated Eclipse libraries, but I only removed some of them. This may need to be reviewed, depending on what versions of Eclipse this project wishes to sustain. Also, I discovered that the formatting of existing source code was space based, with 2-spaces per tab. I updated my Eclipse configuration to have that format, and made it into a project-specific configuration file. This should be put under control, in order to allow all developers to use the same formatting style.
Nov 17, 2008
Regarding the patch, I pulled out a separate patch to one file which fixes up the
annotations and sets the "group" attribute.
Now what is this doing? I tried to capture this in the ticket, but it must not be
very clear.
My original text was
========================================================
In the spirit of "funtional" vs. "broken" vs. "checkin" style (as I read on
the site's documentation), it would be useful is this grouping was prefixed
"functional". For example, in test class TestMyPOJOs, it would be useful to
markup TestMyPOJOs.setUp with
@BeforeMethod(groups="functional.TestMyPOJOs"), each testXXX method with
@Test(groups="functional.TestMyPOJOs"), and so forth. This keeps setUp from
another auto-converted TestSomeOtherPOJOs, from interfering with this test
case.
========================================================
While converting a slew of JUnit tests over to TestNG using the plugin's feature, I
had a pattern I was using, where instead of marking up test methods with just the
annotation, I also put in the groups attribute.
The default behavior would generate this:
class TestClassName {
@Test
public void testThisParticularRun() {
...
}
}
However, I kept going back and manually typing in the groups attribute, in order to
split things up into smaller test blocks. Notice how I use the name of the class as
the key identifier:
class TestClassName {
@Test(groups = "functional.TestClassName")
public void testThisParticularRun() {
...
}
}
This way, I could build my testng.xml file with a "functional.*" rule to capture them
all, and when necessary, run smaller test suites. Instead of doing this by hand, it
seemed easier to let the plugin do this for me, since it obviously had the name of
the enclosing class on hand. It seems like a good default policy of conversion, and
if someone wanted a different pattern, they could either delete the groups attribute,
or plug something else in. At least, they would also be alerted to the option of
grouping test cases together.
Greg
|
5.8 KB View Download