Test Framework

Create and run Apex tests with JetForcer.

In this section, you learn how to quickly create and run a simple unit test. NOTE: at least 75% of your code must be covered by tests before you can deploy it to a production Salesforce org. Generally, JetForcer runs tests by running the Run Configurations you have created. For more usability, the Run commands are provided in certain context menus. For example, these commands are available for a test class or even a directory in the Project View. Moreover, you are able to start testing right from the editor where you are currently working. Create HelloWorldTest.cls test for the HelloWorld.cls class.

    @IsTest
    private class MyHelloWorldTest {
        // Simple test of the method
        // MyHelloWorld.addHelloWorld(Account[])
        @IsTest
        static void test_addHelloWorld() {
            // Set up test data set
            Account testAcct1 = new Account();
            Account testAcct2 = new Account(Description = 'Foo');
            Account[] accts = new Account[] { testAcct1, testAcct2 };

            // Execute code with test data
            MyHelloWorld.addHelloWorld(accts);  // call

            // Confirm results
            System.assertEquals('Hello World', accts[0].Description);
            System.assertEquals('Hello World', accts[1].Description);
        }

        // Simple test of the trigger helloWorldAccountTrigger
        @IsTest
        static void test_helloWorldAccountTrigger() {
            // Set up test data set
            Account testAcct1 = new Account(Name='One');
            Account testAcct2 = new Account(Name='Two', Description = 'Foo');
            Account[] accts = new Account[] { testAcct1, testAcct2 };

            // Execute trigger with test data set
            insert accts;

            // Confirm results
            Account[] acctQuery = [SELECT Description FROM Account WHERE Id = :accts[0].Id OR Id = :accts[1].Id];
            System.assertEquals('Hello World', acctQuery[0].Description);
            System.assertEquals('Hello World', acctQuery[1].Description);
        }
    }