komlaaa
asked on
run program from command line
Hi,
i have a void method(NO Argument) has local variables. i would like to test this
method by imputing these local variables from command line.
Is there a way to do this?
Thanks
i have a void method(NO Argument) has local variables. i would like to test this
method by imputing these local variables from command line.
Is there a way to do this?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
that is not possible to give that argument for method in commandline
You can only run the main method from the command line.
Take the variables from the command line and pass these to the method you want to test from the main method.
public class MainClass{
public static void main(String args[]){
MyClassToTest m = new MyClassToTest();
m.callMyMethodToTest(args[ 0],args[1] ,.......,a rgs[n]);
}
}
command line
java MainClass
Take the variables from the command line and pass these to the method you want to test from the main method.
public class MainClass{
public static void main(String args[]){
MyClassToTest m = new MyClassToTest();
m.callMyMethodToTest(args[
}
}
command line
java MainClass
sorry
you need to initialise the local variables via the constructor
MyClassToTest m = new MyClassToTest(args[0],args [1],...... .,args[n]) ;
m.callMyMethodToTest();
or you need to use Refection APIs to populate the local variables
you need to initialise the local variables via the constructor
MyClassToTest m = new MyClassToTest(args[0],args
m.callMyMethodToTest();
or you need to use Refection APIs to populate the local variables
If the scope of the variables is the method, it cannot be done.