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

Asked

Viewed 331 times

2

I’m trying to create an application that looks like a judge online, but all I want is that after submitting a java file through an html or jsp page, the application runs a certain Junit test case on that java file and shows the results on a new page. I’m having trouble thinking about how best to do this, because I know we can run Junit tests on java files that are already inside the project, but I don’t know how to do it in a java file that is to be submitted in the application database. Does anyone know anything that can help me?

1 answer

2


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

  1. Create an empty project (no classes) in some server directory that has the necessary dependencies, in this case Junit. I suggest using Maven.
  2. Ensures you have JDK and Maven available on the command line
  3. Create an empty class template and provide it to users if you find it necessary.
  4. Every time someone submits a class:
    1. Create a single temporary directory (File.createTempFile)
    2. Run another process in the temporary directory with the command mvn test. Maven must compile the class and run the test class automatically.
    3. Test results are inside the folder target/surefire-reports.

If you want a little security, probably a Docker image and the Maven Docker Plugin to run the tests in an isolated and secure way. However, this will require a little more search and system configuration to work well.

  • Thank you very much for your attention. I found your reply very helpful and I will try to develop it this way. I will comment on the results as soon as I have them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.