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

Books on Testing APEX
I have went through the Apex Language Reference and the Force.com Cookbook but could not find any in depth explanation of how to test Apex code.
The only thing I understand from reading these two sources is that in order to deploy to Apex to production at least 75% of the code must be covered in the test. Then they give a couple of examples of testing code. But there doesn't appear to be any explanation as to why the test examples use the keywords and methods that they are using.
What other sources are there that can further explain in depth how to test Apex?
-Thanks
Other than those two requirements, it is up to you to determine how to test the method; this requires thinking about what your code does and purposefully trying to reach each and every line of code. For example, if you have an "if" statement, make two records or function calls, etc-- one that takes the true branch, and one that takes the false branch. You might need to make If you use try/catch blocks, use one set of records that won't cause the try/catch block to trap an exception, and one that will.
That was a very good explanation, thank you. I now feel I understand the logic of what I am trying to accomplish much better.
I will read up on the try/catch and assert keywords as I am still not familiar with the syntax of these.
One immediate question I have is do you want to use Test.StartTest() when testing a trigger and the testMethod when testing a class, both at the same time? When writing something like public static testMethod void test1 () { } in a trigger there is an error "Only top-level class methods can be declared static".
-Thanks
Now, of course, this is arbitrarily useless code (and may be syntaxically incorrect, as this is only an example), but it does provide an example of how a testMethod would work on a trigger. As you can see, I start by creating two accounts, one to test and make sure that industry would be updated, and one that makes sure that industry would NOT be updated (because it is not blank).