-1

I am running JUnit test for the first time and I get this error message. How can I resolve it?

junit.framework.AssertionFailedError: Could not create test 'should_return_a_set_of_6_numbers_with_no_duplicates' at junit.framework.Assert.fail(Assert.java:50) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader$1.runTest(JUnit3TestLoader.java:177) at junit.framework.TestCase.runBare(TestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Also when I import import static org.hamcrest.Matchers.is; the word is is striked out. What other import can I use to replace it?

I am using STS version 3.6.4.

package net.javavideotutorials.assignment1;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class Tests {


  @Test
  public void should_return_a_set_of_6_numbers_with_no_duplicates ()
  {
    LotteryNumberGenerator sut = new LotteryNumberGenerator();

    Set<Integer> lotteryNumbers = sut.generateLotteryNumbers();

    assertThat(lotteryNumbers.size(), is(6));
  }

}
kryger
  • 12,906
  • 8
  • 44
  • 65
gbbv
  • 1
  • 1
  • 3
  • This is way too little information. What code does your test have, what version(s) are you using? ... – Stultuske May 04 '15 at 13:48
  • Add your spring config file and show us your tests so the community can get a better understanding of why this is breaking. – Matt May 04 '15 at 13:59
  • This is Spring Tool Suite version 3.6.4. Where can I find spring config file? Thanks. I just started learning this. – gbbv May 04 '15 at 16:29
  • Looks like your test case is configured to use the (deprecated and incompatible) JUnit3 runner instead of JUnit4 by your IDE. Knowing this it should be easy to google for a fix (use "eclipse" in search term because STS is based on it). Your project doesn't seem to use Spring Framework so don't worry about "spring config": there isn't any. Hamcrest import not working looks like dependency mgmt problem: should also be easily googlable. – kryger May 04 '15 at 22:06

1 Answers1

0

According to this question, try equalTo:

assertThat(lotteryNumbers.size(), equalTo(6));
Community
  • 1
  • 1
AnnH
  • 43
  • 1
  • 6