Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - @Before and @test annotation

I am very new to Java programming. I have a unit test file to be run. It has annotations of @Before and @Test. I have tried to understand these concepts using available online resources.

When I am debugging my UnitTest.java file, only the @Before part gets executed. It does not reach @Test and the program fails saying:

NativeMethodAccessorImpl.Object(....) not available.

This does not happen when I run the unit tests (as opposed to debugging the unit tests). How do I go about solving this?

like image 479
Samhitha Avatar asked Sep 17 '11 15:09

Samhitha


People also ask

What is @test annotation in java?

The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure.

What is @before annotation in java?

@Before annotation in JUnit is used on a method containing Java code to run before each test case. i.e it runs before each test execution.

What does @before do in java?

The before() method of Java Date class tests whether the date is before the specified date or not.

What is @before annotation in JUnit?

The @Before annotation is used when different test cases share the same logic. The method with the @Before annotation always runs before the execution of each test case. This annotation is commonly used to develop necessary preconditions for each @Test method.


1 Answers

The @Before and @Test annotations are used to define unit tests for the Java JUnit testing framework. See http://junit.sourceforge.net/doc/cookbook/cookbook.htm for an introduction and examples of JUnit unit testing using these annotations.

Your problem is that your have mis-spelled the @Test annotation as @test.

like image 196
Simon C Avatar answered Sep 24 '22 21:09

Simon C