• SF1Dev
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Salesforce Developer
  • Rubicon Global


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I have a method that I need to unit test which retrieves a Static Resource object based on the name of the file passed to the method.  In the unit test, I'd like to insert a new Static Resource, like so:

 

Blob b = Blob.valueOf('file contents here');       
StaticResource resource = new StaticResource(Body=b,Name='testFileName');       
insert resource;

// call method to test with newly created Static Resource
string result = methodToTest('testFileName');

 

 However, it fails when trying to insert the static resource.  How else can I insert it?  Thanks.

Hi all,

 

I tried to test my custom controller, and I got a error message "Variable is not visible" when I saved my test class.

 

Here's a controller.

public class SampleController {
   private User user {get; set;}
   private String pritest {get; set;}
   public String pubtest {get; set;} 
    
   public LoginController () {
      String userid = UserInfo.getUserId();
      user = [select testfield__c from User where id = :userid];
      pritest = 'abc';     

  pubtest = 'xyz'; } public PageReference login() { ・・・・・・・ } }

 

Here's a test class.

@isTest
private class SampleControllerTests {
   public static testMethod void testMyController() {
      Profile p = [select id from profile where name='Standard User'];
      User u = new User(alias = 'standt', email='standarduser@testorg.com', emailencodingkey='UTF-8',lastname='Testing',languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');   
      
      System.runAs(u) {
         PageReference pageRef = Page.SamplePage;
         Test.setCurrentPage(pageRef);

         SampleController controller = new SampleController();

         String pritest = controller.pritest;
         String pubtest = controller.pubtest;
         System.assertEquals('abc', pritest);
         System.assertEquals('xyz', pubtest);
      }
   }
}

Please let me know how to test some private member variables in a class.  

 

 Thanks,

SkyBlue2007