【问题标题】:Salesforce Apex: how to test if trigger was calledSalesforce Apex:如何测试是否调用了触发器
【发布时间】:2016-04-21 19:28:52
【问题描述】:

我在 Apex 中有一个触发器。如何编写检查触发器是否被调用的单元测试?

Account account = new Account(Name='Test account');
insert account;
checkIfInsertTriggerCalled(); // how do I implement this?

【问题讨论】:

    标签: salesforce apex-code apex


    【解决方案1】:

    您应该测试触发器的作用,而不仅仅是它是否被调用。你的触发器有什么作用?

    如果你只是想看看它是否插入那么:

        Account account = new Account(Name='Test account');
        insert account;
        List<Account> aList = [SELECT Id, Name FROM Account];
        system.assertEquals(1,aList.size());
    

    旁注:我本来只想发表评论,但我在这个网站上的代表不足。 编辑:这是链接到很多的标准页面:https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests

    【讨论】:

    • 感谢您的回答!我的触发器发送一个 HTTP 请求。我正在尝试编写一个单元测试来检查请求是否完全发出(而不是它是否正确发出,如 HttpCalloutMock 教程所教的)。以下是我的其他 SO 问题中的更多信息:stackoverflow.com/questions/36778106/…
    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2018-08-17
    相关资源
    最近更新 更多