8

I normally don't experience problem with JUnit annotation. But somehow today, with my new install of Netbeans 7.2, I am experiencing the following error when I use the @Before annotation:

annotation before is missing value for the attribute value

Does anyone know how to fix this?


UPDATE

I am writing a mavenized web-app. For the TestCase, when I try to import org.junit.Before the program instead imports org.aspectj.lang.annotation.Before

kasavbere
  • 5,873
  • 14
  • 49
  • 72

3 Answers3

12

Are you still getting the same error even after adding junit dependency in pom.xml?

Check to see that you are importing the right library i.e.

import org.junit.Before;

instead of

import org.aspectj.lang.annotation.Before;
ssbh
  • 151
  • 1
  • 7
9

Are you declarig a dependency to an up to date JUnit Version?

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
    <scope>test</scope>
</dependency>

You should be able to import the right class: org.junit.Before.

Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118
  • 1
    I am very new to Maven. Is there a way to tell Maven to get the latest version of all dependencies by default? – kasavbere Sep 25 '12 at 02:18
  • 2
    kasavbere, although I deeply recommend you to use concrete library versions - so that new library updates do not break the build, or even worse, introduce subtle bugs at runtime - there are some approaches to do what you want. Refer to his post for further info: http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency. – Anthony Accioly Sep 25 '12 at 02:48
1

This is a pretty old question but for anyone tripping over this error in 2023 after switching to the new JUnit Jupiter or using the latest spring-boot-dependencies bom file (which automatically configures you for Jupiter unless you override it):

Note that as of Jupiter, the org.junit.Before annotation was replaced with the org.junit.jupiter.api.BeforeAll annotation.

Some helpful URL references for the API changes: