Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm going through some test classes that we have in for the extension classes, and I don't understand the test's structure. we set up an instance of the sObject, the controller, and the extension and then invoke methods in the extension class. How does invoking methods like this, actually test code? we're not asserting anything after calling these methods.

As a point of reference, i'm only familiar with testing strategies like assertions

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

You are absolutely correct to question this.

Invoking the methods is not actually testing the code. What it does is increase your code coverage which measures which lines of code have been executed by the test methods. Salesforce only requires code coverage to deploy to production since there is no way for them to check if you are actually testing the code.

You will need to add proper asserts and checking to make these into good test classes.

code coverage requirements for deployment to production:

  • At least 75% of your Apex code must be covered by unit tests, and all of those tests must complete successfully.

    Note the following.

    • When deploying to a production organization, every unit test in your organization namespace is executed.
    • Calls to System.debug are not counted as part of Apex code coverage.
    • Test methods and test classes are not counted as part of Apex code coverage.
    • While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single record. This should lead to 75% or more of your code being covered by unit tests.
  • Every trigger must have some test coverage.
  • All classes and triggers must compile successfully.
share|improve this answer
1  
See also my answer to a previous question on this topic - invoke the method, then assert the expected results. –  metadaddy Feb 11 '13 at 20:47
    
ahh, i see. So this means if that's the bulk of our test classes (not doing asserts, but this stuff), then is that a solid business practice? In effect we're just relying on our QA guys and not doing unit testing. –  nivyaj Feb 13 '13 at 16:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.