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

Test is successfully runs but wont shows any test coverage ..!
Apex class
-------------
public class StringStack {
private List<String> stack;
public StringStack()
{
stack = new List<String>();
}
public void push(String s)
{
stack.add(s);
}
public String pop()
{
return stack.remove( lastItemIndex );
}
public String peak()
{
return stack.get( lastItemIndex );
}
public Boolean isEmpty()
{
return stack.isEmpty();
}
// Helper Property
private Integer lastItemIndex
{
get
{
return stack.size() - 1;
}
}
}
Test clas
------------
@isTest
public class TestStringStack
{
public static testmethod void StringStackcheck()
{
//Instantiate a StringStack.
StringStack stack = new StringStack();
// Set up some test data.
String bottomString = 'Bottom String';
String middleString = 'Middle String';
String topString = 'Top String';
// Call the push() method with multiple objects
stack.push(bottomString);
stack.push(middleString);
stack.push(topString);
// Verify that the 'top' object is the object we expected
String peakValue = stack.peak();
System.assertEquals(topString, peakValue);
// Verify that the order of the objects is as we expected
String popValue = stack.pop();
System.assertEquals(topString, popValue);
popValue = stack.pop();
System.assertEquals(middleString, popValue);
popValue = stack.pop();
System.assertEquals(bottomString, popValue);
System.assert(stack.isEmpty());
}
}
-------------
public class StringStack {
private List<String> stack;
public StringStack()
{
stack = new List<String>();
}
public void push(String s)
{
stack.add(s);
}
public String pop()
{
return stack.remove( lastItemIndex );
}
public String peak()
{
return stack.get( lastItemIndex );
}
public Boolean isEmpty()
{
return stack.isEmpty();
}
// Helper Property
private Integer lastItemIndex
{
get
{
return stack.size() - 1;
}
}
}
Test clas
------------
@isTest
public class TestStringStack
{
public static testmethod void StringStackcheck()
{
//Instantiate a StringStack.
StringStack stack = new StringStack();
// Set up some test data.
String bottomString = 'Bottom String';
String middleString = 'Middle String';
String topString = 'Top String';
// Call the push() method with multiple objects
stack.push(bottomString);
stack.push(middleString);
stack.push(topString);
// Verify that the 'top' object is the object we expected
String peakValue = stack.peak();
System.assertEquals(topString, peakValue);
// Verify that the order of the objects is as we expected
String popValue = stack.pop();
System.assertEquals(topString, popValue);
popValue = stack.pop();
System.assertEquals(middleString, popValue);
popValue = stack.pop();
System.assertEquals(bottomString, popValue);
System.assert(stack.isEmpty());
}
}
But you must use Test.startTest() and Test.stopTest() in your test Class
Update your Test Class with this-- Let me inform if you solve your problem and
If this helps you mark it best answer.
Thanks.
Sandeep
All Answers
But you must use Test.startTest() and Test.stopTest() in your test Class
Update your Test Class with this-- Let me inform if you solve your problem and
If this helps you mark it best answer.
Thanks.
Sandeep
thank you but small clarification When &Why we have to use those methods.!
We have multiple lines in our code so these determines when to start testing of our classes and triggers
for details go to this link--
https://success.salesforce.com/answers?id=90630000000hr9tAAA
Thanks.