Menu

#135 CoupledTestCase incorrectly thrown when referencing the current class

None
open
nobody
None
5
2013-09-19
2013-03-19
Jeff Storey
No

In a test class named MyTest, I call

MyTest.getResourceAsStream

Codenarc marks this as a CoupledTestCase error, but this isn't coupled to another test case, it is simply using the current class' name.

Discussion

  • Chris Mair

    Chris Mair - 2013-04-04
    • status: open --> closed
    • assigned_to: Chris Mair
    • milestone: -->
     
  • Chris Mair

    Chris Mair - 2013-04-04

    Available in CodeNarc 0.19

     
  • Jeff Storey

    Jeff Storey - 2013-09-18

    I just recently upgraded to 0.19. This bug still exists.

     
  • Chris Mair

    Chris Mair - 2013-09-19

    Hmmmm, that is weird.

    This, for instance, is the test case that now passes with no violations:

            class MyTest extends GroovyTestCase {
                void testMethod() {
                    def input = MyTest.getResourceAsStream('sample.txt')
                }
            }
    

    Can you paste in the code that exhibits the error?

     
  • Jeff Storey

    Jeff Storey - 2013-09-19

    This does it:

    package com.sample

    import org.junit.Test

    class MyTest {

    @Test
    void "this is the test"() {
        MyTest.getResourceAsStream("somefile").text
    }
    

    }

    What I noticed is that it does not happen if the class is in the default package. If an explicit package is specified, then it happens.

     
  • Chris Mair

    Chris Mair - 2013-09-19

    Yup, that was it -- the bug fix only works for classes in the default package. Okay, we'll get this fixed.

     
  • Chris Mair

    Chris Mair - 2013-09-19
    • status: closed --> open
    • assigned_to: Chris Mair --> nobody
     
  • Jeff Storey

    Jeff Storey - 2013-09-19

    thanks

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.