【问题标题】:Apex - SalesForce - Writing Test case for a TriggerApex - SalesForce - 为触发器编写测试用例
【发布时间】:2012-04-04 16:01:25
【问题描述】:

大家好, 我是 Apex Development 的新手,目前正在尝试为此触发器编写测试用例。非常感谢任何形式的帮助!

trigger Milestone1_Expense_Trigger on Milestone1_Expense__c (before insert, before update) 
{
    if(Trigger.isBefore)
    {
        Milestone1_Expense_Trigger_Utility.handleExpenseBeforeTrigger(Trigger.new);
    }
}

提前致谢!

【问题讨论】:

  • @superfell 好吧,我正在寻求帮助,而不是“如何提问”的链接。我做了功课,没有发现任何有用的东西,所以我来这里问了这个问题。
  • 你没有提到你尝试了什么,你在哪里看过或任何东西,如果你想要一个有用的答案,你需要提供更多信息。

标签: triggers salesforce apex-code testcase


【解决方案1】:

查看此对Apex Code Test Methods 的介绍,并查找具有http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods 的代码块。该代码部分是测试 Apex 触发器的示例。

【讨论】:

    【解决方案2】:

    查看 matthew 提供的链接。这应该让您了解需要做什么以及如何断言和确认您正在尝试做的事情是否真的发生了。 如果我用简单的方式来解释的话。

    当在 Milestone1_Expense__c 中插入/更新记录时,您的触发器将被触发。 因此,在您的测试类中,您只需为 Milestone1_Expense__c 创建一个测试数据并给出一个插入语句。

    如果我要为 Account 举个例子

        Account a = new Account(Name = 'test', Company__c = 'test');
        insert a;
    

    您可以在此处使用您的自定义对象并使用该自定义对象中的字段来代替 Account

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      相关资源
      最近更新 更多