1

I have been on a search recently for an answer to my question and I cannot seem to find it. I am trying to execute a simple test to run a JUnit test in static. When I try to execute the test I receive the following Failure.

java.lang.Exception: Method SimpleINt()should not be static.

I have JUnit 4 and hamcrest installed and pathsbuilt. (I am still new to Selenium/Java so I am sure there is an easy explanation for this.)

package iMAP;

import org.junit.Test;


public class Test1 {



@Test
public static  void SimpleINt ()
{
    int i = 34;
    System.out.println(i);
}
}
2

2 Answers 2

1

The JUnit documentation for @Test states:

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.

So, what is implicitly said here: the expectation is that @Test is only used for non static methods.

Beyond that: don't use keywords because you can. Learn what they mean. And static is something that you rather avoid (instead of using it all over the place).

Sign up to request clarification or add additional context in comments.

Comments

0

Junit Methods should not be static as much I read and study. Just delete Static and try this:

package iMAP;

import org.junit.Test;

public class Test1 {

@Test
public void SimpleINt ()
{
    int i = 34;
    System.out.println(i);
}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.