@testVisible false negative inspections

Issue #827 resolved
Matt Addy created an issue

It might be strange that Apex allows this, but we've done it throughout some of our code bases.

public class ProductionClass {
    @testVisible private String name;
}

@isTest
private class ProductionClassTest {
    private class ProductionClassStub extends ProductionClass { 
        public ProductionClassStub() {
            this.name = 'foo';
        }
    }
}

The statement this.name = 'foo' is telling us "Cannot resolve symbol 'name'".

Comments (5)

  1. Scott Wells repo owner

    Thanks for reporting, Matt. Strange or not, it's valid syntax. I'll take a look for the next build.

  2. Scott Wells repo owner

    Easily reproduced with the sample you provided. Just had to mark the base class as virtual. Should be pretty easy to address as well.

  3. Scott Wells repo owner

    Aaaannnnd...fixed. All the logic was there, but it was checking to see if the class containing the reference was a test class to decide whether to look at @TestVisible. The inner class isn't a test class even though it's contained within one. I changed it to see if the top-level class is a test class. The fix will be in the next build.

  4. Log in to comment