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
developer srideveloper sri 

Test Class for Enum class

Hi.. Can someone suggest me writing test class for below enum class

 

my Enum class is :

 

public enum ProductType {
   Primary,
   Luxury,
   Sedan
}

 

I tried this but strucked in middle of this, need some help in making >75% code coverage for this.

 

@isTest
Public with sharing class ProductTypeTest{
    Public static testMethod void validateEnum(){
   
    }
}

 

Thanks in advance

 

 

Sonam_SFDCSonam_SFDC

Hi Sri,

 

Please refer to the below link for test class sample code:

http://stackoverflow.com/questions/20112438/how-to-get-code-cover-for-enum-class-in-apex

developer srideveloper sri

Thank you Sonam!!

 

I have seen the link you provided.

 

Here my enum is a direct enum class, but my dout is that, will i need to put my enum in one global/public class, just like this.

 

Global class Utility{

        public enum ProductType{

            Primary,
            Luxury,
            Sedan
}

}

 

I am bit confused with the structure of enum, whether it should a direct enum or it should be in another class i.e child of other class.

 

Please correct me if I was wrong!!!

 

Thank you!!!!

Sonam_SFDCSonam_SFDC

Not necessarily as stated in the following doc:

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_enums.htm

An enum is a data type and it can be used without creating a class..

 

Try testing the enum the way explained in the post http://salesforce.stackexchange.com/questions/20998/how-to-get-code-cover-for-enum-class-in-apex and let me knwo the result..

developer srideveloper sri

As you stated that, enum can be used without creating any class, then how can I address it in Test class

 

We need to address in the Test class as:

 

<Main class Name> .<enum class name> test =  <Main class Name> .<enum class name>.<enum value>

Util.ProductType test = Util.Product.Primary;

Util.ProductType test = Util.Product.Luxury;

Util.ProductType test = Util.Product.Sedan;

 

But in my case, I dont have Main class, then how can I address this in Test class

 

Correct me if i wrong.

 

Very thankful to you if you provide me the test class for

public enum ProductType {
   Primary,
   Luxury,
   Sedan
}

 

Thank you

Sonam_SFDCSonam_SFDC

Sri,

 

Have you created this enum inside a controller?

If yes, ProductType will a property of this controller class.

 

Instantiate the controller class(say we call it con), and you can call this property as follows:

Con.ProductType.Primary

developer srideveloper sri

Hi,

 

I have not created this enum class inside any controller.

 

I have just created as follows and using in some other trigger.

 

public enum ProductType {
   Primary,
   Luxury,
   Sedan
}

 

Thank you!!!!