+ Start a Discussion
Nishad BashaNishad Basha 

how to write the positive and negative test classes in salesforce?

can you give me the examples above scenario.plase give some ideas.
Amit Chaudhary 8Amit Chaudhary 8
Hi Nishad,

Please check below blog. I hope that will help u

Unit Test Mechanism in Salesforce

1) Single action
Test to verify that a single record produces the correct, expected result. So created the unit test data in your test class.

2) Bulk actions
Any Apex code, whether a trigger, a class or an extension, may be invoked for 1 to 200 records. You must test not only the single record case, but the bulk cases as well.

3) Restricted user
Test whether a user with restricted access to the sObjects used in your code sees the expected behavior. That is, whether they can run the code or receive error messages. Always use RunAs for to check user access on sObjects.

4) Positive behaviour
Test to verify that the expected behaviour occurs through every expected permutation, that is, that the user filled out everything correctly and did not go past the limits.

5) Negative behaviour
There are likely limits to your applications, such as not being able to add a future date, not being able to specify a negative amount, and so on. You must test for the negative case and verify that the error messages are correctly produced as well as for the positive, within the limits cases.

Please let us know if this will help you.

Amit Chaudhary
Nishad BashaNishad Basha

Hi, Amit Chaudhary
can you give me the above example of apex class for that code.
Amit Chaudhary 8Amit Chaudhary 8
Hi Nishad,

If we are taking about +ve and -ve test classes it mean we need to create some +ve test data and -ve test data in simple test class.
PLease check below two blog for more information

Please check below post. That will help. Please check below post line by line you will undertand the concept. withe example

Please let us knw if this will help u