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

1 Answer 1


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.
  • 1
    See also my answer to a previous question on this topic - invoke the method, then assert the expected results.
    – metadaddy
    Commented Feb 11, 2013 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. Commented Feb 13, 2013 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .