You need to sign in to do that
Don't have an account?
Mel Lisau
How can i test the else part of an if else statement ?
I have a class with the following layout
if (testflag)
{
//code 1
}
else
{
//code 2
}
When i create a test for my trigger , I set the testflag to true hence it will fall in the code 1 section .
But my overall test dont give full 100% because the else condition is not met ?
Do i need to create another test that meets the else condition , because i dont want to create 2 test for my trigger ?
thanks
if (testflag)
{
//code 1
}
else
{
//code 2
}
When i create a test for my trigger , I set the testflag to true hence it will fall in the code 1 section .
But my overall test dont give full 100% because the else condition is not met ?
Do i need to create another test that meets the else condition , because i dont want to create 2 test for my trigger ?
thanks
how else can you be truly assured that the code works as expected. Remember that test code is there to see how your code would work once it is deployed, so testing of each branch from a start state is best practice. I wonder why the aversion to creating a second test? Once we have one test, a second is easy.
An basic example of some code to cover a basic test class: and if we wanted to be a good developer maybe a test method with a light with status of NULL and then see how well our initial code is written to handle unexpected exceptions.
Regards
Andrew