function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
User UsersUser Users 

Package creation and installation problem

Hello,

I am creating a package with test method and install that package on another account then it will give "Cannot call test methods in non-test context".
How can I resolve it? Without test method I am not able to create package.

Thanks.
bob_buzzardbob_buzzard
Do you see this error on installation or when you have installed and are using the package? That error typically means that you've tried to use a test method as a regular method, which isn't allowed. 
User UsersUser Users
This method come when I installed and are using the package. And I created that method only to create package the method body is blank.
User UsersUser Users
This error come when I installed and are using the package. And I created that method only to create package the method body is blank.
bilal malikbilal malik
i think, u are calling test method from your visual force page thats y u r facing error!!
User UsersUser Users
Here is my apex class

@isTest
global class UserRetrieval{
    static String getUserExtension() {
       List<User> users = new List<User>();
       String uid = UserInfo.getUserId();
       for (User user : Database.query('Select id, extension, username, name from User where id=\'' + uid + '\'')){
           System.debug(user);
           users.add(user);
       }
       String JSONString = JSON.serialize(users);
       return JSONString;
    }
    
    static String getCallerDetail(String extension){
        String JSONString='';
         List<Contact> contacts = new List<Contact>();
        for (Contact contact : Database.query('Select id, name, phone, email, MobilePhone from contact where phone=\'' + extension + '\' or MobilePhone=\'' + extension + '\'')){
            contacts.add(contact);
           }
        if(!contacts.isEmpty()){
            JSONString = JSON.serialize(contacts);    
        }
           return JSONString;
    }
    
    
    static testMethod void testDemo(){}
}

I put testDemo() only to create package. Because without test method I am not able to create package. I am not using testDemo() anywhere in my apex code.
bilal malikbilal malik
ANd where is ur apex class for which u r writing your test cases(i mean this test class which u mentioned above)?
User UsersUser Users
Yes
bilal malikbilal malik
Apex class and Test APex class will be 2 different classes.