简体   繁体   English

在Java版本的Google App Engine中,您如何评估和执行以字符串形式传入的Java代码和单元测试?

[英]In the Java version of Google App Engine, how can you eval and execute Java code and unit tests passed in as strings?

I am currently using an online system running in Google App Engine to enable students to practice coding in python. 我目前正在使用在Google App Engine中运行的在线系统,以使学生能够练习python编码。 The system is inspired by codingbat by Nick Parlante and the public version of Beanshell running on appengine. 该系统的灵感来源于codingbat尼克Parlante和公版BeanShell的 AppEngine上运行。

I would like to extend our system to support Java. 我想扩展我们的系统以支持Java。 In our current system, the Python doctest feature makes it very easy for instructors to type out a series of variable declarations and doctests which can then be executed against student-submitted code. 在我们当前的系统中,Python doctest功能使教师很容易键入一系列变量声明和doctest,然后可以针对学生提交的代码执行这些声明和doctest。 It is very intuitive for the instructors which is important to ensure lots of people are writing tests. 对于讲师来说,这非常直观,这对于确保很多人编写测试很重要。

How do I replace the following comments with Java code to eval and execute tests in Java? 如何用Java代码替换以下注释,以用Java评估和执行测试?

String solution = “a=1;”;
solution += “b=1;”;

String problem = “self.assertEqual(a,1);”;
problem += “c=3;”;
problem += “self.assertEqual(b,2);”;

//eval the solution string
//eval the problem string possibly wrapped by additional junit or other Java code.
//results = Run all the tests
System.out.println(“Test       expected     received   result”);
//For result in results
//  print test, expected, received, result(pass/fail)

Desired output: 所需的输出:

Test                   expected  received  result
self.assertEqual(a,1)  1         1         pass
self.assertEqual(b,2)  2         1         fail

Ideally any number of tests could be included in the problem string above and any number of Java statements could be included in the solution string in order to pass the tests included in the problem string. 理想情况下,上面的问题字符串中可以包含任意数量的测试,解决方案字符串中可以包含任意数量的Java语句,以便通过问题字符串中包含的测试。

To the best of my knowledge, you can't. 就我所知,你做不到。 Compiling Java code at runtime requires access to APIs that aren't available on App Engine; 在运行时编译Java代码需要访问App Engine上不可用的API; that's why things like BeanShell and LOTRepls don't support Java. 这就是为什么BeanShell和LOTRepls之类的东西不支持Java的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM