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
TerminusbotTerminusbot 

@isTest Class: Code Coverage and Argument can't be null error: Issue with SOQL query?

I am in the process of creating a test class on a @future callout. I am running into an issue when the class is fired by the test class it thinks variables are null when I am setting it in the class. 

Here is my test class: 
 
@isTest
public class TestClientQueryCallout {



     @isTest static void testCallout() {
     
        // Set mock callout class 
        Test.setMock(HttpCalloutMock.class, new MockClientQueryResponse());
        
        // Call method to test.
        // This causes a fake response to be sent
        // from the class that implements HttpCalloutMock. 
        Test.startTest();
        ClientBatchQuery.sendBatchQuery();
        Test.stopTest();
        HttpRequest req = new HttpRequest();
        MockClientQueryResponse mock = new MockClientQueryResponse();
        HttpResponse res = mock.respond(req);
        // Verify response received contains fake values
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'text/xml');
        String actualValue = res.getBody();
        String expectedValue = '{"foo":"bar"}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());
    }
}

When it calls 'ClientBatchQuery.sendBatchQuery();' it fails on a variable it finds to be null. Here is a snippet of my class and how I am setting those variables. As you can see I am creating a list that is populated by a SOQL query. When the test class run it triggers an error when it gets to the 'writer.writeAttribute(null,null,'value', account);'. Indicating Argument can't be null. Is there an issue running a test class in conjuction with a SOQL query? 
public static void sendBatchQuery() {    

   	String account;
   	String username;
   	String password;
   	String serverpool;
    //Get Sagitta Info Main Record Data
    List<SagittaInfo__c> sagittaSettings = new List<SagittaInfo__c>([Select Id, Name, account__c, username__c, password__c, serverpool__c, Client_Date__c, Client_GTTIME__c,Client_LTTIME__c, 
                                                                    Client_Sync_Sent__c,Client_Sync_Minutes__c,UniVerse_Time__c,Current_UniVerse_Time__c
                                                                    from SagittaInfo__c where Name = 'MAIN']);
    //Set login credentials for Saggita 
    if (sagittaSettings.size()>0){
     account    = sagittaSettings.get(0).account__c;
     username   = sagittaSettings.get(0).username__c;
     password   = sagittaSettings.get(0).password__c;
     serverpool = sagittaSettings.get(0).serverpool__c;
    }
    
    // Create XmlStreamWriter  
    XmlStreamWriter writer = new XmlStreamWriter();    
            
    //Build PassThroughReq Soap XML 
        writer.writeStartDocument('utf-8','1.0');  
            writer.writeStartElement(null,'soap12:Envelope',null);
            writer.writeAttribute(null,null,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
            writer.writeAttribute(null,null,'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
            writer.writeAttribute(null,null, 'xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope');
                    
            writer.writeStartElement(null,'soap12:Body', null);
                writer.writeStartElement(null,'PassThroughReq',null);
                writer.writeAttribute(null,null,'xmlns', 'http://amsservices.com/');
                    writer.writeStartElement(null,'XMLinput',null);
                        writer.writeStartElement(null,'INPUT',null);
                                writer.writeStartElement(null,'Account',null);
                			    writer.writeAttribute(null,null,'value', account);
                                writer.writeEndElement(); // Account Close
                			    writer.writeStartElement(null,'Username',null);
                			    writer.writeAttribute(null,null,'value', username);
                                writer.writeEndElement(); // Username Close
    						    writer.writeStartElement(null,'Password',null);
                			    writer.writeAttribute(null,null,'value', password);
                                writer.writeEndElement(); // Password Close
                			    writer.writeStartElement(null,'Serverpool',null);
                			    writer.writeAttribute(null,null,'value', serverpool);
                                writer.writeEndElement(); // Serverpool Close
                                writer.writeStartElement(null,'Access',null);
                                writer.writeAttribute(null,null,'statement', 'LIST CLIENTS WITH AUDIT.DATE.TIME GT \\'+ String.valueOf(sagittaSettings.get(0).UniVerse_Time__c) +'\\ *OUTPUT* CLIENT.CODE CAT.CODE.1 CLIENT.NAME ADDR1 ADDR2 CITY STATE ZIP.CODE PRIME.PROD PRIME.SERVICER.NAME PHONE1 PHONE2 EMAIL.ADDRESS');
                                writer.writeEndElement(); // Access Close
                        writer.writeEndElement(); // INPUT Close
                        writer.writeEndElement(); // XMLinput Close
                    writer.writeEndElement(); // PassThroughReq Close
                writer.writeEndElement(); // Soap Body Close
            writer.writeEndElement(); // Envelope Body Close

 
Best Answer chosen by Terminusbot
TerminusbotTerminusbot
I added @isTest (SeeAllData=true) to my method and it looks to have worked.