+ Start a Discussion
somasoma 

Running Tests and Synchronization in Eclipse

I recently installed Eclipse 3.3.1.1 for Java Developers and I installed the Force.com Apex plug-in, as well. I started a new Force.com project and added a new Apex Class, though I added this class under the default "unpackaged" category (so in the package explorer pane it appears under <project name>/src/unpackaged/classes/<class name>.cls). If I right click > Force.com > Run Tests, a dialog appears saying "Operation in progress..." (which closes immediately), and then the "Apex Code Test Runner" pane pops up, but no information appears within the pane indicating any sort of test was run. When I set the "Logging Level" to "Profiling (maximum verbosity)", I see several messages indicating there is no profiling information for SOQL, DML, and method invocations. It's as if the interface runs, but it executes no real analysis.

When I attempt to synchronize, save to the server, or apply the project to the server, the same thing occurs. An "Operating in progress..." dialog pops up, then nothing else occurs indicating anything has happened.

Here's the class I'm attempting to run tests on:
Code:
global class XmlEmailUtil {
 public static String AddXmlTagPair(String name, String value) {
  if (name == null) { return ''; }
  
  return 
   '   <tag_pair>\n' +
   '    <name>' + name + '</name>\n' +
   '    <values>\n' +
   '     <value>' + value + '</value>\n' +
   '    </values>\n' +
   '   </tag_pair>\n';
 }
 
 public static void SendXmlEmail(String id, String body, String toAddress) {
  Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
  
  email.setToAddresses(new String[] { toAddress });
  email.setSubject(id);
  email.setPlainTextBody(body);
  
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
 }
 
 static testMethod void TestAddXmlTagPair() {
  AddXmlTagPair(null, null);
  AddXmlTagPair(null, 'value');
  AddXmlTagPair('name', null);
  AddXmlTagPair('name', 'value');
 }
 
 static testMethod void TestSendXmlEmail() {
  SendXmlEmail(null, null, null);
  SendXmlEmail(null, null, 'cgarrett@p4healthcare.com');
  SendXmlEmail(null, 'body', null);
  SendXmlEmail(null, 'body', 'cgarrett@p4healthcare.com');
  SendXmlEmail('id', null, null);
  SendXmlEmail('id', null, 'cgarrett@p4healthcare.com');
  SendXmlEmail('id', 'body', null);
  SendXmlEmail('id', 'body', 'cgarrett@p4healthcare.com');
 }
}

 

Ron HessRon Hess
you may want to add a debug statement

system.debug('here');

this shoudl then show up in the debug log when you set the log level to debug, then you are sure your code is running.

can you run the test method from the "run test" button in the application ?
what do you see there?

magdamagda
Hi,

I have also problems with Eclipse:
I become on the Apex Code Test Runner: Test coverage of selected Apex Class and Trigger is 0%...
I don't know why.
Another point: Eclipse has for all tags: "unknow tag"

Wen I use Execute Anonymous I have in Result:

Compile error at line 1 column 1
unexpected token: null

Do you have an Idea?

Thx

Magda

somasoma
I attempted to run the tests with System.Debug() in the test methods, but nothing appeared in the debug log.

The only "Run Tests" button I see is in the "Apex Code Test Runner" pane and it say"Re-Run", but this has the same effect as attempting to run the code from the right-click menu.
magdamagda
Hi,

I have also a new Problem:
Code:
AssertionFailedException: assertion failed: ContentViewer must have a content provider when input is set.
assertion failed: ContentViewer must have a content provider when input is set.

 
And what I don't understand in Wiki is:
Code:
Editing and saving an apex trigger/class/page in the absence of an internet connection throws the following assertion failure: AssertionFailedException: assertion failed: ContentViewer must have a content provider when input is set. assertion failed: ContentViewer must have a content provider when input is set.


But i'm using Eclipse in Online Modus....

Do you have an Idea?

Thx

Magda

somasoma
Magda, unfortunately, that exception doesn't seem to make much sense directly, though a bit of research on content viewers revealed a good deal of information for me. I found this page that looks fairly informative.

As for my issue, I discovered the problem. I had been developing in the Salesforce sandbox without the use of Eclipse. Then, when I wanted to port the code from the sandbox to production, documentation suggested there were two options: the ANT tool or Eclipse. Documentation appeared to detail the use of the ANT tooin more words than Eclipse, but I found a number of questions relating to the ANT tool and a few recommendations against its use, so I went the Eclipse route. I created a new project in Eclipse, then added a new trigger and a new utility class, pasting code into those new additions from the code I developed already in the sandbox. For the project, I initially set it up with the URL of the production salesforce server thinking that was appropriate since that's where I wanted the project to live, but this is where the problem was: the URL I specified should have been the sandbox URL. Documentation, in a roundabout way, talks about deploying to production from a sandbox, but it doesn't say that it's required to first set a project up in Eclipse using a testing environment URL. Even more confusing is the fact that Eclipse allows you to set the initial URL for the project to the production server. Doing this, however, causes the strange non-processing issues I mentioned in my original post in this thread. As soon as I changed the URL to the testing environment (the sandbox), I was able to run tests and see code coverage. I was even able to synchronize and save my work to the testing environment.


Message Edited by soma on 02-19-2008 11:45 PM
magdamagda
Hi,

could you please give me the different URLs?

I have already not the posssibility to do this test. Maybe I have to create a new Project...

What I don't understand, I'm able to synchronize and save my code the salesforce... 


Message Edited by magda on 02-19-2008 11:52 PM
somasoma
I honestly just did a search for "eclipse contentviewer" in google (without the quotes) and the first few results seemed pretty informative. One, in particular, which gave a decent amount of information about content viewers in relation to eclipse was this one: http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/compare_contentviewer.htm
magdamagda
sorry but
Salesforce URL: Sandbox URL or Test URL with salesforce....
somasoma
For my project, I was given a choice of three URLs for the SOAP Endpoint (in the project's properties under the Force.com section). They were:

https://test.salesforce.com/services/Soap/u/11.1
https://www.salesforce.com/services/Soap/u/11.1
https://prerelwww.soma.salesforce.com/services/Soap/u/11.1

I chose the first one: https://test.salesforce.com/services/Soap/u/11.1 and then my problems went away. Saving my work and synchronizing all manipulated code in the sandbox, so this URL (https://test.salesforce.com/services/Soap/u/11.1) appears to refer to the sandbox.


Message Edited by soma on 02-19-2008 11:59 PM
magdamagda
Hi

I can use https://www.salesforce.com/services/Soap/u/11.1

But

If i try https://test.salesforce.com/services/Soap/u/11.1 i'm becoming a failure:

Code:
ToolkitConnectionException: INVALID_LOGIN: Invalid username or password or locked out.
INVALID_LOGIN: Invalid username or password or locked out.

If i try to use : https://prerelwww.soma.salesforce.com/services/Soap/u/11.1

Code:
ToolkitConnectionException: UnknownHostException: prerelwww.soma.salesforce.com
UnknownHostException: prerelwww.soma.salesforce.com

 Do you have an Idea?

 

somasoma
Looking at the third URL, it appears to be some odd format based on my name (you see "soma" in it?), so I doubt that would work for you.

The first URL, the test URL, should work for you. I believe you're receiving the invalid username/password error because the format of your username is different when logging into the sandbox. I don't know if you've ever tried to log into your salesforce sandbox on the web, but when you do it takes your username and appends ".apex" to it [edit: it added '.apex' to my username because 'apex' was the name of my sandbox]. So if your username to login to your standard salesforce account is "magda@example.com", then your username to log into your sandbox would be "magda@example.com.apex". Try using this format for your username when using the test.salesforce.com URL.

If that STILL doesn't work, the only other issue I can imagine is that you're experiencing some sort of security token issue, but if you can log into the www.salesforce.com URL without an issue, then I don't tihnk it's a security token issue.


Message Edited by soma on 02-20-2008 01:42 AM
magdamagda
Hi,

i refresh the security token, und add .apex but it is not running...
Allways the same problem :
Code:
ToolkitConnectionException: INVALID_LOGIN: Invalid username or password or locked out.
INVALID_LOGIN: Invalid username or password or locked out.

 Do you think I have to open a case by salesforce?
Oder do you have another Idea?

Thx

Magda

somasoma
You may have to open a case with a Salesforce tech, but before you do, try logging into your sandbox from your browser, first. If you can do that successfully, but you still can't connect through Eclipse, then there is definitely something strange going on.

Regarding the security token, you said you refreshed it. Are you using it? That is, are you appending the security token to the end of your password? I'm sure you're already aware of how to use the security token, but just in case... You may not even need to if you've given your IP network access by adding it to the whitelist in salesforce. But if your IP isn't in that whitelist then you will need to append the security token to your password, of course.
magdamagda
2 questions:

How can I:
- connect to the sandbox from my browser?
       I connect me to Salesforce and I can see my Application, but how can I know which kind of organisation it is?
- adding my IP in whitelist for salesforce?

About Security Token, yes i use the new one.

I have this problem in Eclipse:



Message Edited by magda on 02-20-2008 01:16 AM

Message Edited by magda on 02-20-2008 01:20 AM
somasoma
To log into your sandbox, log into your primary salesforce account then go to Setup > Data Management > Sandbox. There you should find a listing of sandboxes. If you don't see any in the list, you'll have to create one:

1. Click 'New Sandbox'
2. Give it a name, optional description, you can leave just the 'Apex' radio button selected, then press 'Start Copy'.

When you press 'Start Copy', the objects in your production environment are copied to your sandbox environment so you can interact with them like normal. Depending on how many objects and applications you have, this copying process can take a while. Looking at the sandbox listing when the copying is done, in the "Action" column you should eventually see two links: Refresh (this will be inactive at first since you just created this sandbox) and Login. If you click on 'Login', you'll be taken to a login page that looks just like the login to your main salesforce account, but notice two things: the URL is different and your username is different (it has the name of your sandbox appended to it; note, I made an error in my earlier post when I said '.apex' would be appended to your username ['apex' is what I named my sandbox, so that is what was appended to my username]). So, at this login section, supply the same password you use for your main account. With that, you should be able to log into your sandbox. If you were able to do this, then go back to Eclipse and try connecting to the test.salesforce.com URL again.

As for adding your IP to the whitelist, I don't know what sort of permissions you have or in what versions of salesforce you can do this, but for me (I have both administrator access and my company is using Unlimited Edition) I go to Setup > Security Controls > Network Access. If I don't see my IP in the list there, I just add it. With this, I don't have to use a security token when logging in from my computer.


Message Edited by soma on 02-20-2008 01:22 AM
magdamagda
Thx for your answer....

But I don't have the Sandbox in Data Management.

Do you think I have to have this ulimitted edition to be abble to debug my application?
And could you please explain me what is sandbox? I don't realy understand for what is that use....


Thx for your help


Message Edited by magda on 02-20-2008 01:25 AM
somasoma
Are you a system administrator for your salesforce environment? If not, then you won't be able to create a sandbox. If you know who the system administrator for your salesforce environment is, then find out if any sandboxes have been created. It is also a possibility that your organization may have to order sandboxes.
somasoma
This is an addendum to my previous post. According to https://na3.salesforce.com/help/doc/en/create_test_instance.htm sandboxes are available in Unlimited Edition and Enterprise Edition for no additional cost. For other editions, sandboxes will cost extra. This link will also give you a bit of information about sandboxes.
magdamagda
I'm the system administrator

But what is sandbox?

Thx you i had seen this link.

I have a devloper Edition


Message Edited by magda on 02-20-2008 01:38 AM
somasoma
See the last post I made with the link to the sandbox help page. Essentially, a sandbox is a copy of your production environment. It's a good place to run tests without having to worry about damaging any real data you have in your live environment. I'm a bit limited in my own experiences, so I don't know how else you would manage to debug your apex code by running it in the salesforce environment if you're not using a sandbox, but that's what I use it for.
magdamagda
i think to...

Thank you for your very quick answer....
It is very nice.

I will open a case to understand what we have to do to be able to use a sandbox.


somasoma
No worries. Best wishes.
magdamagda
Hi,

I have to create Test Methods.

Do you have en example for test methods in apex classes?
I find online test in s controls, and wenn I want to use this one in my class it is not running.

Do you know how i can do that?

And If you know could you please explain me how i have to write this one.

Thx

Magda

magdamagda
Hi,

it is correct to create a function :

public static testMethod void test()

and insert all what have to be testing in the classes?

Thx

Magda
somasoma
The use of "testMethod" in your example is correct, as well as what you stated about testing all aspects of your code. It can be a difficult process, but you want to be sure that your testing causes all conditionals in your actual code to evaluate to both true and false.

I've only ever run test code on triggers, so that mostly revolves around creating objects, filling their fields, inserting them, modifying the field values and updating the objects again, and repeating this process to cover all if/else conditionals.


magdamagda
o very good ;)
I try to test my trigger, but I don't know how....

My Trigger:

Code:
trigger InitialContactSolution on Object__c (after insert) {
Object__c[] Object = trigger.new;
Class.Function(Object[0]);
}

 My TEst Method:
Code:
public static testMethod void test()
{
try{
System.debug('BEGIN\n');

Function(Object);

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

 But My Eclipse said I cover only 66%.

I thought that i have to insert this object to test the trigger on this object. But it seems to be wrrong...

Do you have another Idea?

Thx

Magda


somasoma
In your testMethod you use Function(Object). Are you doing this in an attempt to test the line "Class.Function(Object[0])"? If so, this won't provide any code coverage as calling Function(Object) within your testMethod in this way only serves to call Function() locally and has nothing to do with your actual code.

You are, however, on the right track in assuming that inserting Object ("insert Object") will cause testing code coverage. Are you actually creating this Object in your testMethod before you pass it to Function() and before you insert it? The way your example code is written, you're using 'Object' like an actual object, but you're not instantiating it or setting any of its properties. I think you may be inserting a null value. If you insert a null value, then when your trigger fires, trigger.new will be assigned to your Object__c[] Object array, but then making a call to Class.Function(Object[0]) would cause a null exception. Though, in reality, if you're trying to insert a null value, I'm not even sure your trigger will fire, but it's certainly possible.
magdamagda
Thx,

I initialiezed my Object... But it is not running... Now there is 0% code coverage...

I don't understand why...
I had values for all field that i need in the FunctionObject
And my trigger bevore and after insert are not covered.
I don't understand why, because I'm duing an insert...

Code:
public static testMethod void test()
{
try{
Object.Field1 = value1;
insert claim;

Object.Field2 = value2;
update Object;

FunctionObject(Object);


}

 

somasoma
Either I'm a bit confused about what you're trying to accomplish with your code or you've been staring at your code too long and you've got a few things mixed up. Based on what I think you're trying to do, here's what the code should look like:

Code:
public class FooTriggerTest {
 static testMethod void TestFooTrigger() {
  Foo__c myFoo = CreateFoo();
  insert myFoo;

  myFoo.Field1__c = 'different value 1';
  update myFoo;
 }

 static Foo__c CreateFoo() {
  Foo__c f = new Foo__c(
   Field1__c = 'value 1',
   Field2__c = 'value 2',
   Field3__c = 'value 3');

  return f;
 }
}

In my code, CreateFoo() is like your FunctionObject() function, creating an object, setting its values, and returning it. Of course, in this function you may apply other logic to create the values, but ultimately it's the same thing. In the code you showed me, it appeared you weren't instantiating your object, rather you were just trying to set field values without allocating a new object first. Anyway, hope this helps.

magalie pickertmagalie pickert
Hi,

Now: Code coverage total %23

And I'm doing the same like you...

I don't understand
somasoma
It's possible your trigger has more logic to it that has to be tested. Remember, if you have any conditional statements, those will have to be made to evaluate to both true and false at some point. I can't help you any further unless I can see the code for your trigger or code that resembles your trigger.
magdamagda
Hi,

thx very much for your help.
Now it is running.
I had forgotten a field and it was a requiered field in the function....

Now I have 100 % Covered


Thx you :)

Magda
somasoma
It's wonderful to hear that you got the 100% coverage, Magalie. I know how I felt when I finally got to that point. I was so happy it was over!

Take care.
magalie pickertmagalie pickert
 :smileyvery-happy: :smileyvery-happy: :smileyvery-happy: :smileyvery-happy:
magdamagda
Hi,

I have a new Problem today.....
I have create a beta package, and I want to install it with another user. I become this failure:

Unable to install this package for the following reasons:


Missing Organization Feature: Solution.RecordType  
Missing Organization Feature: Contact.RecordType  
Missing Organization Feature: Task.RecordType  
Missing Organization Feature: Account.RecordType  


Do you have an idea?

Thx

Magda

somasoma
Sorry Magalie, I have no idea for this one. I think you'll do better to post this up in its own thread in the community. Wish I could help =)