java - Using jUnit to test a class / object which is not created yet -
I am working on a program that would be a kind of game for beginner programmers. I intend to provide an area where users can write codes as necessary (method, class ...). When the user wants to submit the code, then I will copy the content of the text field to a .java file, I will call the compiler to compile this class, and then I want to test whether the code is correct using jUnit Works.
Well, I know that jUnit is used for development purposes, but I think it can be very useful in implementing it in this case too.
The problem now is that when I need to compile my program, the class that can be considered (the user's code) is not going there. So I can not just call
assertEquals ("wrong amount", 6, Foo.sum (4, 2)); Because it will not know what the Fu Class is, since it will never happen at the time of compileat - before the user runs the application and coding begins.
I thought I could make a dummy class just for a compilation, but then when I need the real thing, I will not be able to change the file or write another file like FU2. Java, because FooTest.java will only work with object fu ....
I appreciate your suggestions to people !!! What can I do to deal with this situation?
thanks :)
two options:
< Li> Apply the user interface and use the interface in the zenit - Use the reflection to get a public method from the class and call it.
Reflection version:
If you have an example of a class that you want to test (type can be object ), Then use methods to get a list of class objects then methods to obtain getClass then Change until you want to test (hopefully only public law).
Comments
Post a Comment