function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jezza83Jezza83 

Do I need tests for tests ?

Quick query - I have 80% code coverage on my apex class yet my overall coverage is 70% as it is including my test method....do I need unit tests for my test methods ?
Best Answer chosen by Admin (Salesforce Developers) 
rscottrscott

Test classes need to be marked private. 

 

I've seen test classes marked as less than 100% if you have non-test private methods inside the test class that do not get called by any of the test methods. For example, you created a private method to insert some data to support your tests.

All Answers

m_roarkm_roark

Jdog,

 

If you flag the test method using the 'testmethod' parameter, it should not be counted as code which needs to be covered.

 

Your test method declaration should look like the following:

 

public static void testmethod myTestMethod()

{

//add tests here

}

 

 

Try updating your method to include the 'testmethod' parameter and see if this works for you.

 

Message Edited by m_roark on 02-01-2010 02:09 PM
Jezza83Jezza83

Hi m_Roark,

 

I have declared my test methods as below; 

 

 

@istest

 

private class PanelMaintanenceExtensionTest {

 

static testMethod void massRemoveTest() {

// Unit Tests

}

}

 

Should I be declaring the PanelMaintenanceExtensionTest class as a static void testMethod ?

 

Message Edited by JDog on 02-02-2010 09:39 AM
Message Edited by JDog on 02-02-2010 09:39 AM
Jezza83Jezza83

I have got my total test method coverage to 80% and I can deploy to production fine however the Eclipse IDE still gives me a message

 

! Code Coverage Results

      - (tick)PanelMaintenanceExtension (ApexClass) - 74 Lines not tested, 90% Covered

      - ! PanelMaintenanceExtensionTest (ApexClass) - 55 Lines not tested, 0% Covered

 

Should I be concerned about this ? Am I declaring my test methods incorrectly ?

 

Thanks

m_roarkm_roark

You are declaring your class as 'private'.  I believe test classes have to be declared 'public' in order to be accessible by the testing framework.

 

Try changing your code as below.

@istest public class PanelMaintanenceExtensionTest { public static testMethod void massRemoveTest() { // Unit Tests } }

 


 

Message Edited by m_roark on 02-01-2010 02:52 PM
Jezza83Jezza83
Tried changing to public but received the error: Only private top-level non-exception class types can be marked as tests ??
bob_buzzardbob_buzzard
How are you running your tests from eclipse - are you running tests for a single class, or running all tests for the org?  If the former, I would expect to see coverage warnings as only the tests inside that particular class will be executed.  
rscottrscott

Test classes need to be marked private. 

 

I've seen test classes marked as less than 100% if you have non-test private methods inside the test class that do not get called by any of the test methods. For example, you created a private method to insert some data to support your tests.

This was selected as the best answer
Jezza83Jezza83
Spot on thanks rscott