SalesforceApex:如何测试是否调用了触发器

SalesforceApex:如何测试是否调用了触发器,salesforce,apex-code,apex,Salesforce,Apex Code,Apex,我在Apex有一个触发器。如何编写检查触发器是否被调用的单元测试 Account account = new Account(Name='Test account'); insert account; checkIfInsertTriggerCalled(); // how do I implement this? 您应该测试触发器的功能,而不仅仅是它是否被调用。你的扳机是干什么的 如果您只是想看看它是否插入,那么: Account account = new Account(Name

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

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

您应该测试触发器的功能,而不仅仅是它是否被调用。你的扳机是干什么的

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

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

List

您应该测试触发器的功能,而不仅仅是它是否被调用。你的扳机是干什么的

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

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

列表

谢谢您的回答!我的触发器发送一个HTTP请求。我正试图编写一个单元测试来检查请求是否发出(而不是像httpmock教程那样发出的请求是否正确)。下面是我另一个SO问题的更多信息:谢谢你的回答!我的触发器发送一个HTTP请求。我正试图编写一个单元测试来检查请求是否发出(而不是像httpmock教程那样发出的请求是否正确)。以下是我另一个问题中的更多信息: