I wrote three soql queries in test class
static testMethod void test_DoGet() {
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
User u = [select id,Lastname,ContactId from user where Contactid != null limit 1];
Contact con = [select id,Lastname,AccountId from contact where id=:u.Contactid];
Account acc = [select id,name from account where id=:con.AccountID];
req.requestURI='/services/apexrest/dummy';
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response = res;
}
}
For the User query, it is returning the user. But for the Account and Contact queries, it is showing System.QueryException: List has no rows for assignment to SObject
. I checked in my salesforce edition and it contains many users, Accounts and with contacts.
I tried the above queries like the following.
User u = [select id,Lastname,ContactId from user limit 1];
Contact con = [select id,Lastname,AccountId from contact limit 1 ];
Account acc = [select id,name from account limit 1];
Even though it is showing the same error. If these queries is not covered, then i could not complete total coverage.