What do you need to test modules in Java using Eclipse?

I was recently removed from the .Net world to the Java world, and I missed my unit tests.

Using Visual Studio I used NUnit and TestDriven.net to run my unit tests.

What is a comparable Java system using Eclipse?

I look specifically for plugins that will suit me, or tutorials on how to do this.

I know that JUnit is what NUnit was based on, but I want to know what is the best way to integrate it into Eclipse, as there seem to be a few plugins that do this, and I don’t have time to play with them all.

UPDATE

Well, I did not know that JUnit was built into the development environment. Are there any plugins that make using JUnit easier?

+4
source share
8 answers

Using JUnit with eclipse is actually very simple. Just go to File-> New ... and select the JUnit Test Case. Eclipse will handle the addition of the JUnit library and all imports.

+11
source

What version of Eclipse are you using?

As long as I remember (I used Eclipse from early 3.xs), Eclipse supports JUnit out of the box. You just:

Right click on the project -> Run as -> JUnit Test

This does not work for you?

+4
source

I have been using moreUnit for several years and cannot live without the shortcut Ctrl + J to switch between the class and its test case.

I also found EclEmma useful for finding unverified code.

+3
source

Easier than "Right Click on Project -> Run As -> JUnit Test"? As you want, it is associated with a keystroke (because it probably is). Lemme Check - Yes, alt-shift-X, then "T". Easy?

There is also a / show view / other / java / JUnit window that will give you the junit launcher in the window. Then you can just click the "Test Tests" button and run all the tests in your project / section.

Ctrl-shift-L is great for figuring out key bindings if you get to know eclipse.

Also, get VERY familiar with ctrl-space, just click it whenever you type in the middle of something (seriously, try with everything!) Also enter "sysout [ctrl-space]"

+2
source

I used testNG , which has a plugin for eclipse .

+1
source

JUnit 4 is really very easy to use if you use a project targeting Java 5 or later and add it to the project.

I mean, how much easier can you get than

@Test public myTest() { // Test code here } 

There are also @Before , @After , @BeforeClass , @AfterClass and @Ignore . * Class methods must be static. @Before runs before each test, @BeforeClass runs before the first test ... but keep in mind that JUnit tests can run in any order.

If you are doing database tests, you can look into the DBUnit add-on, although you need to take some special steps to use it in JUnit 4 native mode.

+1
source

fit ( http://www.theserverside.com/news/thread.tss?thread_id=39417 )

dbunit ( http://www.dbunit.org/ )

many other

in eclipse, you can right-click the package and choose to run as a unit test.

be careful http://xunitpatterns.com/test%20fixture%20-%20ambiguous.html . iirc, it comes down to the fact that junit creates an instance of each test case before calling setup and nunit, just creating one instance.

+1
source

What do you mean by "make using JUnit easier?"

I use Ant for runnings tests as a task. The output will be saved to a flat file or html file. It depends on the TestRunner.

Please specify your question and you will get answers! :)

+1
source

All Articles