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
magalie pickertmagalie pickert 

HELP !! !! Test Methods

Hi,

I have a problem egarding Test Methods.
I'm becoming this error: No testMethods found in the selected Apex code for the package
And it is regarding my bevor insert trigger
Trigger BeforInsertObj on Obj__c (before insert)
And my code contains an insert statment:
Code:
public static testMethod void test()
{
try{

User user = new User();
Obj.Editor__c = user.Id;


System.debug('Add a Obj\n');
insert Obj;

Obj.Priority__c= 'Low';
Obj.Schedule_Time__c = Date.valueof('2008-12-01');
update Obj;

InsertTask(Obj);


}
catch (DmlException e) {
   System.debug(e.getMessage());
   }
   
}

 

Do you have any Idea?

Thx

Magda






magalie pickertmagalie pickert
Hi to explain more:

Code not covered: Line 103 Column 20.
On this line is : public static Task InsertTask(Obj__c obj)

And what I don't understand is why because in my TestMethod I have this code:

Code:
task.xxx = xxx
…
insert task;
Task task2 = InsertTask(obj);
System.assertEquals(task, task2);

I change the test Method to:


Code:
task.xxx = xxx

insert task;
InsertTask(obj);
Task task2 = [select id, WhatId, OwnerId, Subject from task where Id = :task.Id];
System.assertEquals(task, task2);

But nothing is changed. COde not covered for insertTask :(

 

Do you have an idea?





Message Edited by magalie pickert on 10-01-2008 01:20 AM

Message Edited by magalie pickert on 10-01-2008 01:34 AM
magalie pickertmagalie pickert
Hi,

i fand the problem in my test•
Now I have

Code coverage total %89
with o test failures.

in my testmethod is trigger also tested.

I try to do an upload and i become the same failure of my trigger:

No testMethods found in the selected Apex code for the package

Do you have an Idea

PLEASE HELP ME!
jrotensteinjrotenstein
You'll need two bits of code:
  • Your Trigger
  • An Apex class that tests your trigger
 I don't know what is in your Obj__c and I don't know what you're trying to test, but here's an example of a Trigger:
Code:
Trigger BeforInsertObj on Obj__c (before insert) {
for (Obj__c o : Trigger.new) {
// Do something on the objects
}
}

Then, you'll have a separate Apex class that tests the Trigger:
Code:
public class TriggerTest {

public static testMethod void TestObj() {

// Create a new Obj__c
Obj__c Obj = new Obj__c(Priority__c = 'Low',
Schedule_Time__c = Date.valueof('2008-12-01'));

insert Obj;

// Retrieve the Obj__c
Obj_c Obj2 = [select id, xxx from Obj__c where Id = :Obj.Id];

// Test that the trigger worked
System.assertEquals('Success', Obj2.xxx);

}
}

The main idea is:
  • Have your Trigger do whatever the Trigger does
  • Create a separate class that contains a TestMethod
  • The TestMethod creates/updates the object that activates your Trigger
  • After the insert/update, retrieve the object again and test that the Trigger did whatever it was meant to have done
You then run the tests on the class containing the TestMethod.
magalie pickertmagalie pickert
Hi,
thx for your help…
But I allready have this.

I have a code coverage 91% !

And my Debug Log :
Code:
Debug Log
 *** Beginning Test 1: qaas.newGatheringController.public static testMethod void test()

20081002050537.670:Class.qaas.newGatheringController.test: line 47, column 1: Add a Task
. . . . . . 


20081002050537.670:Class.qaas.newGatheringController.test: line 80, column 1: Insert: SOBJECT:qaas_Obj__c
*** Beginning qaas.BeforInsertObj on Obj trigger event BeforeInsert for null

20081002050538.626:Trigger.qaas.BeforInsertObj: line 8, column 1: In trigger

20081002050538.626:Trigger.qaas.BeforInsertObj: line 9, column 1: SelectLoop:LIST:SOBJECT:qaas__Obj__c
20081002050538.626:Trigger.qaas.BeforInsertObj: line 14, column 5: 0037000000boWoMAAU
. . . . 

*** Ending qaas.BeforInsertObj on Obj trigger event BeforeInsert for null


*** Beginning Obj Validation Rule Evaluation for null

 

And my Failure:
Code:
Apex Trigger BeforInsertObj No testMethods found in the selected Apex code for the package

 


I don't understand becose my Test is testing the trigger (see debug)








Message Edited by magalie pickert on 10-01-2008 10:14 PM
jrotensteinjrotenstein
I'd have to see all your code to understand what is happening -- both your Trigger and your Test class.

Also, are you triggering on Obj__c or Task? And what class are you selecting when you run your Tests?
magalie pickertmagalie pickert
I'm triggering on obj__c
magalie pickertmagalie pickert
My class:
Code:
public class newGatheringController {
..
public static testMethod void test()
{
..
insert Obj;
..
update Obj;

InsertTask(Obj)
}
..
public static void InsertTask(Obj__c obj)
{
..
}

 


My Trriger Name
Code:
Trigger BeforInsertObj on qaas__Obj__c (before insert){
..
}

 

My Debug Log
Code:
 *** Beginning Test 1: qaas.newGatheringController.public static testMethod void test()
..
*** Beginning qaas.BeforInsertObj on Obj trigger event BeforeInsert for null
..
*** Ending qaas.BeforInsertObj on Obj trigger event BeforeInsert for null
..
*** Ending Test qaas.newGatheringController.public static testMethod void test()

 


Thx

Magalie d'Anterroches
magalie pickertmagalie pickert
I change now my TestMethod and I have 100 % coverage.

And I have yet the same failure by upload my package:
No testMethods found in the selected Apex code for the package

:(

Magalie d'Anterroches


jrotensteinjrotenstein
It's still a little hard to understand things without seeing all your code.

Is your trigger on Obj__c or qaas_Obj__c?

Your Trigger says Trigger BeforInsertObj on qaas__Obj__c but the debug log shows qaas.BeforInsertObj on Obj trigger.

Why are your assert tests based on Task rather than Obj__c?

How are you running the tests? Are you running ALL tests? if so, which class/module is giving you the the "no testmethod" error?


magalie pickertmagalie pickert
Hi,

my trigger is on API Name qaas_Obj__c.

In my class a create an Obj:
Obj__c Obj = new Obj__c();

That's why it is in the debug: qaas.BeforInsertObj on Obj trigger.


I created an asset on InsertTask because it is a method in my class and it was not covered. But now it is covered.


Do I have to create an asset on my Obj too?
jrotensteinjrotenstein
You should create an assert to test whatever it is that your Trigger is meant to be doing.

I'm still confused why you don't have the same Object type as your "on" as the object you are triggering, eg:

Trigger BeforInsertObj on Obj__c

since that's the object that you are inserting.
magalie pickertmagalie pickert
i do that allready but the problem is staying