Am I missing any step somewhere?
I am pasting my code here :
package test;
import static org.junit.Assert.*;
public class Test {
@Test
public static void main(String[] args) {
// TODO Auto-generated method stub
assertEquals(0, voidMethod(), 0);
}
static int voidMethod()
{
return 0;
}
}
Thanks in advance
You need to import the junit Test class. Use this:
import org.junit.Test;
It would also be best to name your method something other than Test
so as not to conflict with this import.
Also, you can't use a static method as a Junit test method and your Junit tests shouldn't have arguments. You will get an exception stating that the test method should not be static, and the test method should not take parameters.
The whole point of Junit Tests is that you have many individual tests that can be run independently of each other. You don't have any arguments passed into the test. Everything you need should be set up in the test or before the test using one of the @Before
annotations.
Try something like this:
package test;
import static org.junit.Assert.*;
import org.junit.Test;
public class TestClass {
@Test
public void myTestMethod() {
// TODO Auto-generated method stub
assertEquals(0, voidMethod(), 0);
}
static int voidMethod()
{
return 0;
}
}
unfortunately I had put same name to my class as 'Test' which was actually crating problems..
Thanks a lot...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.