You need to sign in to do that
Don't have an account?
jmburns
Why wont this work?
Trying to upload this test class, but i am getting an error that apex test coverage is only 74%..which is why im trying to upload this test class lol..... any ideas? I am including the clas it is testing below....
Appreciate any help!!
Thank You
@isTest private class tableSortTest { private static void test() { Account a = new Account(name='Test'); insert a; List<Task> tasks = new List<Task>{ new Task(Subject='A Task',ActivityDate=System.Today(),Status='Completed',WhatId=a.id), new Task(Subject='Z Task',ActivityDate=System.Today().addDays(-1),Status='Not Started',WhatId=a.id)}; insert tasks; Test.setCurrentPage(Page.Sort); Test.startTest(); ApexPages.currentPage().getParameters().put('id',a.id); tableSort controller = new tableSort(); System.assertEquals(2,controller.getOpps().size()); controller.sortField = 'Subject'; controller.doSort(); System.assertEquals('A Task',controller.getOpps()[0].Subject); controller.doSort(); System.assertEquals('Z Task',controller.getOpps()[0].Subject); controller.sortField='ActivityDate'; controller.doSort(); System.assertEquals(System.Today().addDays(-1),controller.getOpps()[0].ActivityDate); controller.sortField='Subject'; controller.doSort(); System.assertEquals('A Task',controller.getOpps()[0].Subject); Test.stopTest(); } }
public class tableSort { public List<Task> opps; public Id theT; public String sortField {get; set;} public String previousSortField {get; set;} { theT = ApexPages.currentPage().getParameters().get('id'); } public List<Task> getOpps() { if(opps == null){ opps = [select WhatId, Subject, OwnerId, Description, ActivityDate from Task WHERE WhatId = :theT ]; } return opps; } public void doSort(){ String order = 'asc'; /*This checks to see if the same header was click two times in a row, if so it switches the order.*/ if(previousSortField == sortField){ order = 'desc'; previousSortField = null; }else{ previousSortField = sortField; } //To sort the table we simply need to use this one line, nice! superSort.sortList(opps,sortField,order); } }
You forgot the testmethod keyword in your method line. Also you don't need the private keyword on it.
All Answers
You forgot the testmethod keyword in your method line. Also you don't need the private keyword on it.
Thank you