English 中文(简体)
Run JUnit automatically when building Eclipse project
原标题:

I want to run my unit tests automatically when I save my Eclipse project. The project is built automatically whenever I save a file, so I think this should be possible in some way.

How do I do it? Is the only option really to get an ant script and change the project build to use the ant script with targets build and compile?

Update I will try 2 different approaches now:

  1. Running an additional builder for my project that executes the ant target test (I have an ant script anyway)
  2. ct-eclipse, recommended by Thorbjørn
最佳回答

For sure it it unwise to run all tests, because we can have for example 20.000 tests whereas our change could affect only, let s say 50 of them, among which are tests for the class we have changed and tests for classes that collaborate with our class.

There is an unseful plugin called infinitetest http://improvingworks.com/products/infinitest/ which runs only some tests ( related to class we ve changed ) just after we save changes. It also integrate quite nicely with editor ( using annotations ) and problem view - displaying not-passing tests like errors.

问题回答

Right click on your project > Properties > Builders > New, and there add your ant ant builder.

But, in my opinion, it is unwise to run the unit tests on each save.

See if Eclipse has a plugin for Infinitest.

I d also consider TestNG as an alternative to JUnit. It has a lot of features that might be helpful in partitioning your unit test classes into shorter and longer running groups.

I believe you are looking for http://ct-eclipse.tigris.org/

I ve experimented with the concept earlier, and my personal conclusion was that in order for this to be useful you need a lot of tests which take time. Personally I save very frequently so this would happen frequently, and I didn t find it to be an advantage. It might be different for you.

Instead we bit the bullet and set up a "build server" which watches our CVS repository and builds projects as they change. If the compilation fails or the tests fail we are notified quickly so we can remedy it.

It is as always a matter of taste what works for you. This is what I ve found.

I would recommend Inifinitest for the described situation. Infinitest is nowadays a GPL v3 licensed product. Eclipse update site: http://infinitest.github.com

Then you must use INFINITEST. INFINITEST helps you to do Continuous Testing. Whenever you make a change, Infinitest runs tests for you.

It selects tests intelligently, and only runs the ones you need. It reports unit test failures like compiler errors, and provides additional information that helps you write better tests.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签