How can I design online tests and prevent cheating? As you may know, schools in many parts of the world will remain closed for a long time due to the coronavirus outbreak.

In Italy, the government has invited schools to provide remote teaching, and since many schools are subscribers of G Suite or Office 365, teachers are giving online lessons using web conferencing services (Google Hangouts Meet or Microsoft Teams).

Now, the main problem is with tests.

Regarding computer science, if we know that "it is spectacularly easy to cheat on computer science labs" (and in my tests students have to write code on paper), we can just imagine how simple is to cheat in an online test, whether it is an assignment to be submitted after several days, or a few minute quiz.

A different assignment for each student is not a solution, since lazy students could ask clever students to solve their assignment, so I think I am forced to abandon tests which require students to write their own code.

Maybe a better idea could be a quiz with automatically generated questions, like a code snippet and the request to determine the output for a given input, with different input values and variable names for each student.

Do you know any tool to create such questions? Or do you have any other suggestions?
I don't think there are any published tools to generate programming assignments, though there are articles that describe such tools (such as this one from a CUNY, or this one from Croatia, so one option is to try to contact those authors and find out whether they would share their results with you.)
I will state categorically that there is no way of guaranteeing that students will not cheat.  As the old saying goes, &quot;locks are to keep honest people honest.&quot;  Putting road blocks in the way of cheating will help dissuade students from trying, both because it becomes more of a bother, and because it gives them a chance to remind themselves of the ethics involved.
The bit about ethics is important, actually, and it can be remarkably effective all on its own.  Dan Ariely did an excellent set of studies about this, which he summarized hilariously in this TED talk.  If you don't want to watch that, then you can read this blurb from his blog, though the talk is well worth the time and much more interesting.

&quot;We used an honor code in an experiment at MIT in 2007. We asked a few hundred undergraduates to do some simple math problems but didn’t give them enough time to finish. We then asked them to score their own tests and tell us how well they had done, with payment of $1 for each question they reported getting right. The students were asked to shred their papers afterward—but our shredder didn’t really work, so we could see how they had done. Many cheated. We had a second group of students follow the same procedure but only after they first signed the honor code. Signing the honor code before the test eliminated cheating altogether.
The effectiveness of such a code doesn’t stem from signing it, though. It comes from being reminded about moral issues. If your students eventually stop thinking about the ethics code as they sign it, it will lose its power. If they keep reading and reflecting on the code, its effectiveness might increase.
I ask my own students to write their own version of an ethics code—not because I’m especially interested in their interpretations but because it helps to ensure thought.&quot;
Dan Ariely

So, one way of working around the COVID-19 problem is to combine both ethical thinking and a few roadblocks to help gently dissuade cheating:

Remind students about ethics up front, at the top of your exam. (I make them copy out, by hand, an honor statement.  On a computerized exam, I would provide an image of the statement and make them type it.)
Schedule the exam in advance.  Give the exam at a specific time, and a narrow window (say, 10 minutes) to begin the exam.
There is no need to make different exercises for each student.  Make 3 programming problems, and assign each student to different problems using a rule.  This decreases the chances that they will have a friend in the class with the same problem.
Require that the exam be finished within a reasonable time from the start time.

It's not foolproof.  They could, for instance, have their parent sitting next to them, telling them the answers.  But you can't do anything about such a scheme.  What you can do is set up roadblocks and set the stage for ethical action on the part of your students.  If Ariely's studies are any guide, you should get the large majority of students to submit honest work this way, and that is probably the best you can hope for.