1

I would like to write a web application that would work like that. One user upload unit tests, the other user uploads testable code, the server runs the tests over the code then and save the results. I need hint how to run tests over the code on the server and/or is there any other way how to do it better ?

Tom
  • 21
  • 2
  • 3
    Why do you need to make it exactly this way? Usually people commit code and tests to git. Then some CI/CD tool e.g. jenkins/gitlabci runs it. If all tests passed, then you deploy your code to server. – Ivan Lymar Nov 25 '19 at 20:05
  • I'm not much familiar to CI and tests on git. The thing is that the hole process should be very easy also for people who don't know how to use a git, code should be uploaded by one person and tests by anyone else, not by one person. Is this possible to do using any CI tools ? if yes I could just make some simple web form for upload and the push would be made by web app. – Tom Nov 25 '19 at 20:35

1 Answers1

1

I would not go with approach that you described. It has bunch of problems to solve:

1) Make sure that code provided by user is secured. E.g. you don't want code provided by user to shutdown the server.

2) Let's suppose you figured out how to make provided code secure. Now you have to figure out how to run it.

3) You need to store test reports somewhere and handle failures somehow... If tests fail, you may want to rollback server changes.

4) It's error prone. Since user provides just plain string, he may make typos in classnames, method names, imports and 100 other things.

These are most obvious problems, I think people can come up with others.

I would just follow standard practice:

1) One person writes code AND unit tests ( or one pair in case of pair programming).

2) Same person commits it to VCS ( nowadays VCS is a must )

3) Build automation tool should build it and run tests. ( if you don't have/know it, you can just build project locally).

4) After all build steps were executed ( manually or automatically ) you should decide if you want to deploy your code. Not tested code should not be deployed at all ( there is an opinion that broken code should not be even committed to release branch )

p.s.

Approach that you described might be valid only in case if you are developing some coding practice website, where people provide solutions to coding tasks. In that case you would have predefined list of tests which will be ran on users provided code.

Ivan Lymar
  • 2,180
  • 11
  • 26
  • Thanks a lot for all your points. My idea is almost exactly what you are talking about in p.s. The "lecturer" would upload set of tests and provide interface to be implemented. And the "student" would implement interface so that a code contains required methods which are gonna be tested. – Tom Nov 25 '19 at 22:06
  • 1
    It's not recommended to show test cases to the student, just test case names. Since student might hack tests and create fake code that will satisfy tests, but not real requirements. It's better to make student to upload code. Anyway you can use list of problems as a TODO list and ask specific questions to get more specific answers. – Ivan Lymar Nov 25 '19 at 22:22
  • That is a realy good point, thanks a lot. But my main problem is how to test uploaded code. Do you think that it would be possible to use a CI tool a.g. Jenkins or which mechanism or technology should I use for that purpose ? I don't even know where to start, so I ask for some basic concept. – Tom Nov 25 '19 at 22:50
  • https://stackoverflow.com/questions/4389232/run-piece-of-code-contained-in-a-string I would start from this. – Ivan Lymar Nov 26 '19 at 14:41