Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3086

Class level TestNG Test annotation on a groovy class does not work as expected

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.7, 1.6-beta-2
    • 1.6-rc-1, 1.5.8, 1.7-beta-1
    • groovy-jdk
    • None
    • Microsoft Windows XP [Version 5.1.2600]
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
      Groovy Version: 1.5.6 JVM: 1.5.0_04-b05

    Description

      Groovy runs a class as a testNG test only if at least one method is annotated with org.testng.annotations.Test. If the @Test annotation is only done at the class level, the class is not recognized as a TestNG test class.

      I looked into it and found that org.codehaus.groovy.vmplugin.v5.TestNgUtils.realIsTestNgTest() checks only method level annotations) to determine if a class can be run as a TestNG test class.

      Example code:

      import org.testng.annotations.Test;
      
      @Test
      class GroovyTest {
      	void willPass() {
      		assert 1 == 1
      	}
      }
      

      The code above fails with following error:

      Caught: groovy.lang.GroovyRuntimeException: This script or class could not be run.
      It should either: 
      - have a main method, 
      - be a JUnit test, TestNG test or extend GroovyTestCase, 
      - or implement the Runnable interface.
      

      Reference: http://www.nabble.com/Groovy-and-TestNG---not-possible-to-add-%40Test-annotation-to-class-td19936696.html#a19936696

      regards,
      Roshan

      Attachments

        1. Test3086.groovy
          0.5 kB
          Roshan Dawrani
        2. Groovy3086Patch.txt
          2 kB
          Roshan Dawrani

        Activity

          People

            paulk Paul King
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: