I have created a LWC component, it has 1 Apex class that is test covered at 100%. However when I try to create my package, it fails saying "No test methods found in the Apex code included in the package. At least 75% test coverage is required." for my class.
When I run sf apex run test --wait 100 --code-coverage
I get ComunikAppletApexClass 100%
, ComunikAppletApexClass
being the Apex class from my component.
Here's my test class, it is contained in a file located in the same folder as my Apex class.
@isTest
private class TestComunikAppletApexClass {
@isTest static void testCreateCallLog() {
Account acct = new Account(Name='Test Account');
insert acct;
Contact contact = new Contact(LastName='Test Contact', AccountId=acct.Id);
insert contact;
Task callLogReturned = ComunikAppletApexClass.createCallLog(contact, 'test', 'Outbound', 'http://test.url/');
Task callLog = [
SELECT
Id, WhoId, Description, Priority, Status, Subject, CallType, Type, TaskSubtype
FROM Task
WHERE Id = :callLogReturned.Id
];
System.assertEquals(callLog.WhoId, contact.Id);
System.assertEquals(callLog.Description, 'http://test.url/');
System.assertEquals(callLog.Priority, 'Normal');
System.assertEquals(callLog.Status, 'Completed');
System.assertEquals(callLog.Subject, 'test');
System.assertEquals(callLog.CallType, 'Outbound');
System.assertEquals(callLog.Type, 'Call');
System.assertEquals(callLog.TaskSubtype, 'Call');
}
@isTest static void testGetContactByPhoneNumber() {
Account acct = new Account(Name='Test Account');
insert acct;
Contact contact = new Contact(LastName='Test Contact', AccountId=acct.Id, Phone='1234567890');
insert contact;
Contact contactReturned = ComunikAppletApexClass.getContactByPhoneNumber('1234567890');
System.assertEquals(contactReturned.Id, contact.Id);
}
private static final String FAKE_RESPONSE_JSON = '{"status": "ok"}';
private class Mock implements HttpCalloutMock {
public HTTPResponse respond(HTTPRequest req) {
HTTPResponse res = new HTTPResponse();
res.setBody(FAKE_RESPONSE_JSON);
res.setStatusCode(200);
return res;
}
}
@isTest static void testLoginUser() {
Test.setMock(HttpCalloutMock.class, new Mock());
Test.startTest();
String responseJSON = ComunikAppletApexClass.loginUser('[email protected]', 'test');
Test.stopTest();
System.assertEquals(FAKE_RESPONSE_JSON, responseJSON);
}
}
I feel like I am doing something wrong but I don't understand what.