I need a newbie's introduction to junit: What does jUnit actually do?

I am just starting out in Teams for Education. I notice that there are some useful assessment tools to test for I/O and stuff, and I am interested in the Unit tests, since I would like to test my student’s functions for boundary conditions and the like.

However, I have no idea what the intent is of jUnit. So, I will submit my use case, and you can tell me if this is do-able.

A student in grade 10, who isn’t yet making their own classes, creates functions in replit which return a value. Of course they are writing these in class Main, and are told to declare them as “public static” before their return type.

Can I test those functions in jUnit? I would suppose that I have to declare a “Main” object variable with something like

Main m = new Main();
// Main has a public static int function called x
int q = m.x(99); // call a function x inside of Main.

… to call the functions inside of it. Is anything I am saying on the same planet as anyone else who is properly using jUnit? Otherwise, what is jUnit good for?

I have no clue about jUnit, and its documentation appears to lack a brief summary of what it is meant to test and who would be interested in using it, so I would appreciate a “basic-level” answer. The above code would work well for a testbed, but I would have to copy/paste it into each one of my student’s projects. I am hoping that jUnit would automate this, but my attempts at doing the same thing under jUnit have failed.

Paul

You are barking up the right tree here. If you have ever used codingbat, you will understand the value of JUnit. You create tests, which the students run to check their code for correct output. Example: Run the method named add with the arguments 2 and 3. If the method returns the value 5, you pass the test. If it returns any other value, you fail the test.

In my experience, setting up unit tests is very time consuming, especially during the process of learning how to do this. It pays massive dividends in the end though, because it not only automates the grading process, but even more importantly, it gives the students instant feedback.

I have found that Replit’s implementation of unit testing is pretty clunky. I really wish you could just upload a functional java file with the tests already built. Maybe they have changed this, but it used to be that you had to copy and paste individual tests each into its own section. It was set up like a form that you fill out. This gets pretty time consuming when you have 50 or more tests, which is not uncommon or overkill. I also hate doing work that I know will not transfer over to another system. (i.e. something other than Replit) Right now, I am teaching my CS classes using Eclipse, and this is one big reason why.

2 Likes

Were you able to get jUnit testing to work for you? I have a few simple tests (new to Replit Teams) but can’t find how to add them. The starter videos only contemplate python and js. The testing interface just tells me ‘no test found’ but not where to add it … ty

I think that jUnit was intended for Java, unless I am wrong. That is how I had been using it. I haven’t used jUnit in any but the most simple use cases either, but it has bee helpful in helping students debug a function or object to spec, largely through the use of AssertEquals. I never saw videos on this; only read the jUnit documentation, which is the first place I would recommend to go.

Yes, JUnit is for Java. What language are you using?