junit4

Junit test case: Connection refused case

Hi all, I am writing a Junit(4.x) test to test what happens when the web application is down. When I hit the url in the browser, I get a message saying "Connection refused". I am unsure about what to check for in the assert statements. Do I check the header for this message? -- urlConnection.getResponseMessage() or just say (exp...

How can I use TestSuites with Junit4?

I can't seem to find any documentation on how to do this that actually explains how to invoke the testsuite. So far I have this: package gov.hhs.cms.nlr.test; import java.util.LinkedList; import org.junit.runner.RunWith; import gov.hhs.cms.nlr.test.marshalling.InquiryMarshallingTest; import junit.framework.Test; import junit.fra...

How can I recursively find and run all Junit 4 tests within Eclipse?

I would like to run all junit 4 tests within my Eclipse project. The project is setup with /source and /test. Under /test are various packages, such as: com.yaddayadda.test.core.entity com.yaddayadda.test.core.framework If I right-click at the /test level in Package Explorer and choose Run As; Junit Test I receive the error: No te...

How to run test methods in spec order in JUnit4?

I want to execute test methods which are annotated by @Test in spec order. For example: public class MyTest{ @Test public void test1(){} @Test public void test2(){} } I want to ensure to run test1() before test2() each time I run MyTest, but I couldn't find annotation like @Test(order=xx). I think it's quite important featur...

groovy, Junit4 unit test, and related test runner

I'm trying to write Junit4 test cases for my Groovy code. The Junit 4 test case works fine inside my Eclipse IDE which is SpringSource Tool Suite. I can't get a test running to run the all of the test cases, however. Here is my current attempt at a test runner. It's pretty much taken directly from the Groovy website itself: import g...

manage thread with junit4

hello, with Junit4, i tried to write a test (.class) that contains 3 @test and need to open the appli in each test so in the function init that start the appli and close it : @BeforeClass public static void setupOnce() { final Thread thread = new Thread() { public void run() { //start the appli in the main thread.start(); } } } @...

write a clean junit4 tests

with junit test , how could I start the application software then close it properly and do it for each test ? @test public void test1(){ // start appli //test Jtextfield //close appli } @test public void test2(){ // start appli //test ComboBox //close appli } @test public void test3{ // start appli //test Jbutton //close appli } ...

is it possible to make test method parameterized, not an entire class?

As I understand, with JUnit 4.x and its annotation org.junit.runners.Parameterized I can make my unit test "parameterized", meaning that for every set of params provided the entire unit test will be executed again, from scratch. This approach limits me, since I can't create a "parameterized method", for example: .. @Test public void t...

Pass parameters to Junit Class from Ant

Hi, I'm using Junit under ant to perform Selenium Test.My test cases need to read files which contain test data(in order to accomplish data driven test). I don't mind embedding the file names in the test cases, but I'd like to have the name of the directory where the data files are stored parameterized in the build.xml file. What's the...

producing a correct and complete xml unit testing report (for Hudson)

I'm extending RUnit (a unit testing suite for R) so that it produces also output that can be read by Hudson. actually I already have something that does this, but it does not handle 'deactivated' tests. to see what I mean, have a look at the r-forge project 'rtest' (it temporarily identifies itself as RUnit, but it further works rather...

Why is a junit test that is skipped because of an assumption failure is not reported as skipped?

I use junit assumptions to decide whether to run a test or not. Tests where the assumption fails are ignored/skipped by the junit framework. I wonder why skipped tests are not reported as 'skipped'? Please have a look at the example: import static org.junit.Assert.fail; import org.junit.Assume; import org.junit.Test; public class Ass...

How to run JUnit Eclipse Plugin tests with JMock?

Hello, I have Eclipse plug-in and junit tests for it, which are using jMock library. When I run my test 'as junit', all tests are running correctly. But when I run them 'as JUnit plugin test' I'm getting the following error: java.lang.TypeNotPresentException: Type [unknown] not present at sun.reflect.annotation.TypeNotPresentException...

JUnit Theory problem

Hello, I am writing a test case where in I want to run a one DataPoint for one test case and second DataPoint for second test case. @RunWith(Theories.class) public class DummyTest { @DataPoints public static String[] getFileNames() { return new String[] { "firstFile.txt","firstFile1.txt" }; } @Theory publi...

Junit 3 to JUnit 4 conversion

I had the following version of a test in JUnit 3, and I tried converting it into JUnit 4, with no success. The idea is to have a base test case, that does the actual test of an interface, say Service interface. I want to test the ServiceImpl class, using the base test case. public abstract class ServiceBaseTest extends TestCase { p...

write a simple junit4 test

hello, I tried to write a simple junit test as follow : @before public void start(){ MyAppli.OpenResults(); } @Test public void test1(){ File.OpenFile(); } @After public void closeappli(){ MuAppli.close(); } but when I run the junit test, it launched the appli then stop test without doing File.OpenFile(); and what is also done in @aft...

how to manage exception with JUnit4 ?

hello, my JUnit test is as follow : public class Toto{ @BeforeClass public static void initTest1() { try{ openAppli(); }catch(Exception e){ e.printStackTrace(); } } @Test public void test1(){ try{ //do some actions }catch(Exception e){ e.printStackTrace(); } } @AfterClass public static void AfterTest1() { CloseAppli(); } ...

whas the actual use of 'fail' in junit test case?

whas the actual use of 'fail' in junit test case? ...

Migrating JUnit JPA tests from Spring 2.5.5 to Spring 3.0.4

Our project has just decided to migrate from Spring 2.5.5 to Spring 3.0.4. In my original code, I had unit tests that looked like the following: public class RequisitionDaoTest extends AbstractJpaTests { public static String FAIL_MSG_UNEXPECTED_ERROR = "FAIL: Unexpected Error"; @PersistenceContext private EntityMa...

junit 4 testing with spring 3.0 and Hibernate 3 in Eclipse - LazyInitializationException

I'm getting a LazyInitializationException trying to test my DAO methods using the tool stack defined in the title. My understanding is that my test must be running outside the hibernate session, or it has been closed before I try to read children objects from my DAO. From reading the documentation, I understood that using the @Transact...

junit 4 TransactionalTestExecutionListener insert test data only once for all tests in class?

I have a junit 4 test class testing a DAO. unit test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:/WEB-INF/applicationContext-db.xml", "classpath:/WEB-INF/applicationContext-hibernate.xml", "classpath:/WEB-INF/applicationContext.xml" }) @TestExecutionListeners({Depe...