Tuesday, July 31, 2012

Snippet to generate lines for TestSuite

I wanted to generate the TestSuite for all my classes and was not ready to click on all 200 test classes to generate from eclipse So wrote a small testcase which printed the lines for me to add into my TestSuite. Here is the code snippet.



    @Test
    public void testShouldPrintAllTheNameOfTestClasses() throws Exception {
        File dir = new File("/Project/DIF/dif_parent");
        LinkedList files = (LinkedList)FileUtils.listFiles(
                  dir,
                  new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$"),
                  DirectoryFileFilter.DIRECTORY
                );
        for (File file: files) {
          System.out.println("suite.addTestSuite(" + file.getName().replace("java","class" ) + ");");
        }
    }



Thanks
Manisha

No comments:

Post a Comment