Skip to main content

JUnit

Metadata

This task is complementary to the lectures and lists tasks and information for the in-lesson tasks.

Get started

  1. Clone the example project
git clone --branch 1.1.0 https://github.com/nds-swe/jinder.git \
&& cd jinder
  1. Read the readme.md
  2. Open the file src/test/java/ch/abbts/nds/swe/swdt/jinder/nottdd/MatcherTest.java

Task

Task

Fill the method public void matchNone(){}

There are some comments that help you get started.

Java anonymous interface

Candidate c = new Candidate() {
@Override
public String[] getSkills() {
return new String[]{"skill1", "skill2"};
};
};

This creates on the fly an implementation of the interface Candidate that you can use for these tests. In your application, you can use real classes or fixtures (hard-set test data) of course. We can shorten this way because this lesson is about writing a first Unit Test and not typing off code.

Sample solution

Here.

An additional fix was added to leverage JUnit5's tagging system.

In the sample there are two more examples of Unit Tests.

  • matchOne tests the case that at least one skill matches
  • matchTwo tests two matches, but independent from their order (which is wanted here)