🔧 Build it · 100 XP
Your first test class
Your first class and test
Anonymous Apex is great for experimenting, but real code lives in classes. And Salesforce won't let you deploy to production unless your tests cover at least 75% of your code.
public with sharing class Greeter {
public static String greet(String name) {
return 'Hello, ' + name + '!';
}
}
A test class looks like this:
@isTest
private class GreeterTest {
@isTest
static void greetsByName() {
Assert.areEqual('Hello, Quill!', Greeter.greet('Quill'));
}
}
Your mission
Create these in your org, using the Developer Console (File → New → Apex Class), VS Code or sf project deploy start:
AQ_Greeterwithpublic static String greet(String name)greet('Quill')returns'Hello, Quill!'- a blank name returns
'Hello, mysterious Trailblazer!'(useString.isBlank)
AQ_GreeterTest, which passes and covers ≥ 75% ofAQ_Greeter
Then hit Submit. Quill will call your method and run your tests in your org.
🦝 Test both branches and you'll hit 100%. Quill notices these things.