What is the use of a Junit before and Test package in java? how can i use it with netbeans?
- If I understood you correctly, you want to know, what the annotation - @Beforemeans. The annotation marks a function as to be executed before each test will be executed. There you can implement the old- setup()procedure.
- The - @Testannotation marks the following method as a JUnit test. The testrunner will identify every method annotated with- @Testand executes it. Example:
import org.junit.*;
    public class IntroductionTests {
        @Test
        public void testSum() {
          Assert.assertEquals(8, 6 + 2);
        }
    }
- how can i use it with netbeans?In Netbeans, a testrunner for JUnit tests is included. You can choose it in your Execute Dialog.
Hi,
Can you be more precise? Do you need to understand what are @Before and @Test annotation?
@Test annotation is an annotation (since JUnit 4) that indicates the attached method is an unit test. That allows you to use any method name to have a test. For example:
@Test
public void doSomeTestOnAMethod() {
  // Your test goes here.
  ...
}
The @Before annotation indicates that the attached method will be run before any test in the class. It is mainly used to setup some objects needed by your tests:
(edited to add imports) :
import static org.junit.Assert.*; // Allows you to use directly assert methods, such as assertTrue(...), assertNull(...)
import org.junit.Test; // for @Test
import org.junit.Before; // for @Before
public class MyTest {
    private AnyObject anyObject;
    @Before
    public void initObjects() {
        anyObject = new AnyObject();
    }
    @Test
    public void aTestUsingAnyObject() {
        // Here, anyObject is not null...
        assertNotNull(anyObject);
        ...
    }
}
Testing-Associates.
We employ best of technology products as a key enabler for bolstering productivity, achieving better time-to-market and improving software quality. We are extreme agile in our development processes with unmatched details for product quality.