Adding JUnit and Hamcrest for Testing in Java
package test.string; import java.lang.String; import static org.junit.Assert.assertThat; import org.junit.Test; public class StringFormatTestCase { @Test public void testNumberFormattingWithLeadingZeros() { final String formatted = String.format("%04d", 1); assertThat(formatted, equalTo("0001")); } @Test public void testDoubleFormattingWithTwoDecimalPoints() { final String formatted = String.format("%.2f", 12.324234d); assertThat(formatted, equalTo("12.32")); } }
Errors
Error:(3, 33) java: package org.junit does not exist Error:(3, 2) java: static import only from classes and interfaces Error:(5, 25) java: package org.junit does not exist Error:(6, 12) java: package org.junit does not exist Error:(12, 10) java: cannot find symbol symbol: class Before location: class edu.kit.ipd.swt1.StringFormatTestCase Error:(17, 11) java: cannot find symbol [...]
In order to fix it we had to Open Module Settings for that project and manually add jar Dependencies junit-4.12.jar and hamcrest-core-1.3.jar which are contained in the IntelliJ installation lib directory (C://Program Files/JetBrains/lib/xxx.