简体   繁体   中英

Netbean is opening Junit3 template instead of Junit4

I'm Using Netbean for Java Assignment (for School) and doing Unit Test (JUnit) yesterday. When i added New > JUnit Class, it used to open Java Class starts with ...

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class UtilsClass {
...
}  

But Today When i add New > JUnit Class. it opens Java Class starts with

import junit.framework.TestCase;

public class NewEmptyJUnitTest1 extends TestCase {
.....
}

i know both are Junit Class but i really want back the 1st one as i'm used to it. i have done complete uninstallation of Netbean and reinstall it.

Ok it's an old question but since I had the same problem right now, I think it is worth an answer. Maybe it is also useful for others.

I observed that if I create a new plain project in NetBeans, create a class and create a test class from it by right clicking the class -> Tools -> Create/Update Test, a JUnit4 test class is created. This leads me to the following solution:

  1. Ensure that you have the correct library included in your project's TestLibraries folder, if not right click the TestLibraries folder, remove the JUnit3 library and replace it with the JUnit4 library, which you can download here: https://junit.org/junit4/ . (note that JUnit4.12 has a dependency on the hamcrest 1.3 library, anyway both libraries are already present in the NetBeans 8.2 installation)

  2. Asuming that you already had the correct libraries included and the problem still exists, as it was for me. You can check the NetBeans project properties file <NetBeans-Project-Location>/nbproject/project.properties . Within this file you may find the property junit.selected.version=3 you can eigther change this to 4 or delete the whole line.

  3. Save the file. If you now create a test class the JUnit4 tamplate will be picked.

Enjoy writing your JUnit4 tests. ;)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM