You need to sign in to do that
Don't have an account?

Pls give me the small example for test classess using system assert and asserequals.
Hi,
i just want to understand writing the test classes using assert equals and assert.so kindly give me the small example in vf.
Thanks
Put in the context of a simple class
Then you'd use an assert to confirm the behaviour of the constructor like so:
Thanks Bob,
i would like to know that, for every time creating test classes using assertequals,we need to define constructor?
and why we are using system.assertequals and assert for test classess? so pls let me know so that i can understand easily.
You don't need to define constructors etc. Asserts are a way of confirming that the code is behaving as expected. For example, you may invoke a method that writes information to the database. In your test class you would execute the method, retrieve the record from the database and use asserts to confirm that the record field values are as expected.
There are two aspects to unit testing on Force.com
- coverage, ensuring that your tests execute at least 75% of the code you wish to deploy. However, all this test is that the code runs without failing.
- confirmation - this is where asserts come in. Your tests should confirm that the code behaves as expected, effectively adhering to contracted behaviour. The benefits of confirmation are (a) ensuring the code works as you think it should (b) catching any changes that would stop it behaving as expected (and thus breaking downstream code)