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
mukesh khandvemukesh khandve 

Classes and their test classes eaxmples?

Raj VakatiRaj Vakati
Here is the simple apex class
 
public class TemperatureConverter {
    // Takes a Fahrenheit temperature and returns the Celsius equivalent.
    public static Decimal FahrenheitToCelsius(Decimal fh) {
        Decimal cs = (fh - 32) * 5/9;
        return cs.setScale(2);
    }
}

Here is the test class
 
@isTest
private class TemperatureConverterTest {
    @isTest static void testWarmTemp() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(70);
        System.assertEquals(21.11,celsius);
    }
    
    @isTest static void testFreezingPoint() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(32);
        System.assertEquals(0,celsius);
    }
    @isTest static void testBoilingPoint() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(212);        
        System.assertEquals(100,celsius,'Boiling point temperature is not expected.');
    } 
    
    @isTest static void testNegativeTemp() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(-10);
        System.assertEquals(-23.33,celsius);
    }
      
}

Refer this links

https://trailhead.salesforce.com/content/learn/modules/apex_testing/apex_testing_intro​​​​​​​
mukesh khandvemukesh khandve
I want more example for test classes 
mukesh khandvemukesh khandve
I have completed that trailhead I want more example for test classes 
Raj VakatiRaj Vakati
Refer this links

https://www.tutorialspoint.com/apex/apex_testing.htm
https://webkul.com/blog/test-classes-in-apex-salesforce/
Deepali KulshresthaDeepali Kulshrestha
Hi Mukesh,

Refer to these links for apex class with its test classes.

http://www.sfdcpoint.com/salesforce/test-class-with-example-salesforce/
https://webkul.com/blog/test-classes-in-apex-salesforce/
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
https://www.tutorialspoint.com/apex/apex_testing.htm

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha