• Home
  • RSS Feed
  • Log in

Eclipse Tip: Keep static imports for JUnit 4
Posted by Vincent Partington in the early evening: October 12th, 2008

If you are using Eclipse to write your JUnit 4 tests you might have noticed that when you organize the imports, the line


import static org.junit.Assert.*;

at the top of your JUnit 4 classes is replaced by stuff like:


import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;

While your code still compiles and runs OK, this forces you to add another specific static import every time you want to use another static assert method like assertEquals.

Luckily this can be fixed by going to Windows/Preferences..., going to the Java/Code Style/Organize Imports tab and then entering 1 where it says "Number of static imports needed for .*" and then clicking the OK button.

Hope this helps!

  • Share/Bookmark

Filed under Java | 6 Comments »



6 Responses to “Eclipse Tip: Keep static imports for JUnit 4”



    p3t0r Says:
    Posted at: October 12, 2008 at 7:40 pm

    Also, add ‘org.junit.Assert’ or any of your static helper methods to your ‘favorites’ (preferences, search for favorites). This makes working with static imports much easier.



    Martin Tilma Says:
    Posted at: October 13, 2008 at 9:05 am

    I just wrote on the same issue (http://www.func.nl/community/knowledgebase/eclipse-and-static-imports) but the solution differences a bit.



    p3t0r Says:
    Posted at: October 13, 2008 at 9:13 pm

    @Martin Tilma … that is exactly what I said in my first comment… but thanks for elaborating ;)



    Vincent Partington Says:
    Posted at: October 14, 2008 at 9:13 am

    Hey guys, thanks for that tip! I hadn’t seen that option yet, but it seems an even easier solution to the problem. Especially when other people on your project don’t have the setting I mentioned and reformat the code which removes the star again. (You know who you are! ;-) )



    Ron Says:
    Posted at: October 20, 2008 at 2:10 pm

    Great tip!
    cheers, Ron



    Eclipse and JUnit 4 Static Imports « Developers, Developers, Developers! Says:
    Posted at: February 12, 2010 at 9:18 pm

    [...] idea taken from http://blog.xebia.com/2008/10/12/eclipse-tip-keep-static-imports-for-junit-4/ Tagged as: Eclipse, JUnit 4 Leave a comment Comments (0) Trackbacks (0) ( subscribe to [...]



Leave a Reply

Click here to cancel reply.

Deployment automation for Java application running on Websphere, WebLogic and JBoss

Archives

  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India

Categories

  • Java (282)
  • Agile (109)
  • General (50)
  • Testing (42)
  • Performance (42)
  • Hibernate (36)
  • Scrum (33)
  • Podcast (31)
  • Architecture (31)
  • Spring (28)
  • SOA (24)
  • Maven (22)
  • Project Management (22)
  • Middleware (23)
    • Deployment (14)
  • Flex (17)
  • JPA (17)
  • Eclipse (15)
  • Xebia Labs (15)
  • Quality Assurance (14)

Tag Cloud

    Xebia Scrum Performance SOA Agile Functional Programming Hibernate Semantic Web Testing Architecture Lean Agile Awareness Workshop Closures Seam Java Grails Scala Maven IntelliJ JavaOne esb Spring Introduction to Agile Poppendieck product owner Groovy qcon XML fitnesse Ajax