One of my new projects at work is to ramp up a way to get our J2ME stuff under tests with JUnit. I’ve used NUnit quite a bit now, but hadn’t had a chance to get up to speed with JUnit. I found a nice article on getting JUnit running with Eclipse. The article is a tad old, but pretty straightforward. If you want a quick rundown, here it is:
- Install Eclipse from eclipse.org.
- File->New->Project…->Java Project
- Name it whatever you want, and choose Next
- Click on the “Libraries” tab
- Click “Add External JARs…”
- Choose $ECLIPSE_HOME/plugins/org.junit_3.x.x (or whatever the junit version is)/junit.jar
- Click Finish
Now your project has the JUnit jar on the classpath. Creating a test is very easy:
- File->New->JUnit Test Case
- Name it whatever you want – say TestThatWeGetHelloWorldPrompt to borrow from the article. Choose the method stub for main and “Add TestRunner Statement for text ui”
- Create a basic testWorks – public void testWorks(){assertTrue(true);}
- Save the file (autocompile)
- Choose Run->Run As->JUnit Test
- Watch the Green Bar pass