You need to sign in to do that
Don't have an account?

Test Class Assertion Failed: Expected: Sent, Actual: draft
Hi All,
I've written a trigger for Orders where whenever I send an email through the Order the status in the order from 'draft' will become 'sent'. And it works like a charm. My trigger is :
My problem is with the test class. After modifying my calss alot of times I came to a result where System.AssertException: Assertion Failed: Expected: Sent, Actual: draft
My class is
I've written a trigger for Orders where whenever I send an email through the Order the status in the order from 'draft' will become 'sent'. And it works like a charm. My trigger is :
trigger TaskTrigger on Task (after insert) { List<Order> ordersToUpdate = new List<Order>(); for(Task t : Trigger.new) { if(t.WhatId.getSObjectType() == Order.sObjectType && t.Subject.startsWith('Email:')) { ordersToUpdate.add(new Order(Id = t.WhatId, Status = 'Sent')); } } update ordersToUpdate; }
My problem is with the test class. After modifying my calss alot of times I came to a result where System.AssertException: Assertion Failed: Expected: Sent, Actual: draft
My class is
@isTest public class Test7{ public static testmethod void TaskTrigger_Test1() { Account a = new Account(Name = 'Test'); insert a; Id pricebookId = Test.getStandardPricebookId(); Product2 prd1 = new Product2 (Name='Test Product Entry 1',Description='Test Product Entry 1', isActive = true); insert prd1; PricebookEntry pe=new PricebookEntry(UnitPrice = 1,Product2Id=prd1.id,Pricebook2Id=pricebookId,isActive=true); insert pe; Order o = new Order(name='Test1',AccountId=a.id,EffectiveDate=system.today(),status='draft', PriceBook2Id=pricebookId); insert o; OrderItem oi = new OrderItem(OrderId=o.id,Quantity=1,PricebookEntryId=pe.id, unitPrice=1); insert oi; Task t = new Task(whatid=o.id,Priority = 'normal',status='open',subject='Email:xxxx'); insert t; system.assertequals('Sent',o.status); } }
In order to check whether your trigger executed as expected in a test method, you need to do a query to get the resulting record back again. So you need something like
and then assert on oret, not your original o.
All Answers
In order to check whether your trigger executed as expected in a test method, you need to do a query to get the resulting record back again. So you need something like
and then assert on oret, not your original o.