Create web application that runs JUnit test cases in java files that will be submitted by a page?

2

I'm trying to create an application similar to an online judge, but all I want is that after submitting a java file through an html page or jsp, the application runs a certain JUnit test case in that java file and shows the results in a new page. I'm having trouble figuring out the best way to do this, since I know that we can run JUnit tests in java files that are already inside the project, but I do not know how to do it in a java file that is to be submitted in the database. application. Does anyone know of anything that can help me?

    
asked by anonymous 22.02.2016 / 17:02

1 answer

2

Regardless of the security involved, this can even be easy. However, do not try to run within your application.

  • Create an empty project (no classes) in any directory on the server that has the required dependencies, in this case JUnit. I suggest using Maven.
  • Ensures that you have JDK and Maven available on the command line
  • Create an empty class template and provide it to users if needed.
  • Each time someone submits a class:
  • Create a single temporary directory ( File.createTempFile )
  • Run another process in the temporary directory with the command mvn test . Maven should compile the class and run the test class automatically.
  • The test results are inside the target/surefire-reports folder.
  • If you want a bit of security, probably a Docker image and the Maven Docker Plugin to run the tests safe and secure way. However, this will require a little more research and configuration of the system to work well.

        
    23.02.2016 / 02:17