function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ranjan nagaraju 7ranjan nagaraju 7 

Defining type for testMethod methods must be declared as IsTest

public class JSONObject {
    public class value {


public class JSONException extends Exception {}

public class JSONTokener {

    public static  testmethod void test_valueToString() {
        Make sure that the JSON rendered by this class passes validation by parsers
        from and
        For example:    {foo: "bar"} is invalid
                        {"foo": "bar"} is valid

getting below exception 

Error: Compile Error: Defining type for testMethod methods must be declared as IsTest at line 15 column 36

if i try adding @isTest method  end up with this error 
Compile Error: testMethod are by default IsTest at line 16 column 36

Can someone please help with this
ranjan nagaraju 7ranjan nagaraju 7
tried adding @isTest Annotation on at JSONObject class  it resolved the issue , but will it affect non test function or classes
Are you trying to write a test class here 
public static  testmethod void test_valueToString() {
Narender Singh(Nads)Narender Singh(Nads)
hi ranjan,
Am not sure what exactly you are trying to achieve but if you are writing a test class then use @istest annotation at the beginning of the parent class.
ranjan nagaraju 7ranjan nagaraju 7
it is legacy class so on update i have to move this test method into new test class.but accessing inner class inside my test class is the issue now .
i.e. in my case  earlier i was able to declare inside above class JsonObject.JsonTokener tkr = new  JsonTokener('//ff \n{}');
but outside the class how i can create variable of jsonTokener
Sam jeshwin rajSam jeshwin raj
Try Changing the Version of Apex like less than 29 try 23,25.
It will work.
@sam - Thanks sam,...infact it works