5
$\begingroup$

I was hoping that in this year's Software Engineering class, our capstone for Computer Science, could implement a disciplined automated test strategy for their Java project. Now, with only seven weeks left my students have not gotten that started.

I figured that jUnit, because it's so widely used, would be relatively accessible. However, it seems to have a lot of complexity. Specifically, the inexperienced DevOps students — who only work 18 days before switching teams — would have to dive into Maven or Gradle to get the correct artifacts.

Also, when programming my students would need to ramp up almost instantly on Java annotations, when many of them are relatively inexperienced.

I am dying for some kind of Java unit-testing package that will:

  • easily plug in to a project as one or two JAR files
  • allow students to adapt their own tests quickly by using a Test interface of some sort
  • have a minimal framework that will run all the tests and emit the results

Maybe there's a wrapper for jUnit that will do this? I don't know.

Thanks in advance for any suggestions.

$\endgroup$
4
  • 3
    $\begingroup$ Note that JUnit was developed to support "test first" or "test driven development". Are you willing to do that? An implication is that assignments need to be differently structured. $\endgroup$
    – Buffy
    Commented Mar 23 at 11:56
  • 6
    $\begingroup$ Maven and Gradle are popular Java project management and build tools. Their popularity is well earned, but as far as I am aware, they are not essential to using JUnit, or most other Java frameworks. I confess, that most of my first-hand experience with JUnit dates mostly to before Maven and Gradle existed, but I'm pretty sure you can still do things the old-school way: manually download JARs and put them in the classpath. $\endgroup$ Commented Mar 23 at 13:10
  • $\begingroup$ @Buffy I've sketched TDD for the class but it's impossible in a 16-week semester. $\endgroup$ Commented Mar 24 at 14:40
  • $\begingroup$ @JohnBollinger jUnit 5 ("jupiter") doesn't actually list the JARs at all, it basically says "Maven or Gradle"? $\endgroup$ Commented Mar 24 at 14:41

3 Answers 3

4
$\begingroup$

Good on you for adding this into your class! But I admit that sounds it like a lot in a short time to me.

My only practical thoughts are to (1) provide some starter code that gets the lab project going and also provides some sample tests, and (2) temper your expectations of the tests that the students do produce being very good.

Oh, and give lots and lots and lots of gradle support. For students new to gradle, that is a bit like landing on a foreign planet.

Learning to write tests, at least the mechanical part, isn't so hard if the setup is done and there is a model. JUnit is fairly straightforward! But learning to create a good test suite takes far longer to learn, and there's as much art to it as science. You can (and should!) give them some guidance, but I'd still grade that aspect quite gently.

$\endgroup$
1
  • $\begingroup$ Yes, thank you. I might be able to whip up some kind of setup — but isn't that what jUnit (or TestNG) should do out-of-the-box? $\endgroup$ Commented Mar 24 at 14:42
2
$\begingroup$

If you are willing to use TDD, even in an elementary course there is a solution. I've used it, though with older students.

On the first day of the term, give a demo about how to develop a piece of software using test first but with only small pieces of a larger program. Describe how the test tests requirements and then writing a small piece of the program makes the tests pass. One or two tests. A few lines of code.

Then, when you give assignments, instead of giving them as a narrative describing the entire program, divide it up into "stories" as is done in Extreme Programming,

The display initially has zero value.

When a number key is pressed, the display takes that value.

Etc.

Then have the program built in the order of those stories.

Using this technique you can, in parallel, introduce the programming concepts that you need in the course.

Another way to say this is that you don't, initially, have the students divide up the required program into individual parts/tasks. You do that for them. At some point you can make the stories bigger and require more in problem decomposition but that also helps them understand that problem decomposition and program composition are different if complementary processes.

I also incorporated pair programming into this, but you may not want to go that far.

$\endgroup$
1
$\begingroup$

JUnit is indeed independent from Maven or Gradle. You can get the jars here: https://junit.org/junit5/

Once this is added to the classpath, you need to add a run configuration to execute the tests instead of the main program.

IntelliJ IDEA and Eclipse both have integrated support for JUnit (including a small GUI showing the status etc.). I think you do not even have to download something.

Having some kind of kickstart Test as template would surely be helpful. JUnit does not provide such. But the documentation has probably something you can use as blueprint.

Writing tests comes down to apply the JUnit logic to the code to test. This involves some understanding of the JUnit concepts (TestCase, TestSuite, Test Coverage, Test Stub/Scaffold, best practices for writing testable code, etc.) and also knowledge about the JUnit API (all the assert methods). The former probably takes some thought to plan for but giving examples for the API usage should be straight-forward to understand.

If I recall correctly, our programming course had JUnit presented within one or two weeks of lectures and writing tests was not mandatory, except for one lab exam. But there was also a dedicated/advanced course for code tests you could take. This had all the in-depth theory and also lab and a quiz/exam at the end. These are the extreme cases you can have, I think. Supposedly your approach lies somewhere in between.

Having at least heard of JUnit is a benefit even for DevOps, I suppose. Maybe having a small project in which you need to write tests for one selected class only (not all of them) is already sufficient to present some basics.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.