0
@isTest
public class test6 {
static testmethod  void test()
{
string check;
system.debug(Test.isRunningTest());   
if(Test.isRunningTest())
check='Test7';
else
check='tyftdytfyudd';
}
    //system.debug(check);
}

While Saving the Apex Class:

Error: Compile Error: Method does not exist or incorrect signature: Test.isRunningTest()

  • Please Anyone Guide Me for the Answer – Elavarasan Mar 30 '16 at 12:35
6

Most likely you created an Apex Class before with the name Test, which will force the compiler to look at your class and try to find the isRunningTest() method instead of the standard Apex class.

4

Test.isRunningTest() is meant to be used in the class that the test is testing not in the test class itself. See the docs here for more information on that method.

Returns true if the currently executing code was called by code contained in a test method, false otherwise. Use this method if you need to run different code depending on whether it was being called from a test.

Found a helpful article here that goes over examples of when to use the method.

Other Usage scenarios:

1) To ensure the trigger doesn't execute the batch if Test.IsRunningTest() is true, and then test the batch class with it's own test method.

2) Testing callouts - in your callout code you check to see if you're executing within a unit test context by checking Test.isRunningTest() and instead of getting your callout response from an HttpResponse.send() request, you return a pre-built test string instead.

0

Did you add a class to your org named Test?

If you add an Apex Class with the same name as a default class in Apex, all calls to that class will look at your class instead of the standard Apex classes.

  • please display the code or Answer,i am not able to Understand – Elavarasan Mar 30 '16 at 12:46
  • 2
    @Elavarasan Your testmethod is called test (line 3 in your question)... try renaming it. – Girbot Mar 30 '16 at 13:26
  • @Girbot By Renaming the Method also shows same error,please Help – Elavarasan Mar 30 '16 at 13:33
  • Others above have already said this but you most likely have another class/method called test - find it and rename it. – Girbot Mar 30 '16 at 13:49
  • @Elavarasan go to Setup -> Develop -> Apex Classes, do you see a class with the name "Test"? – Jenny B Mar 30 '16 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.