Все вопросы: [junit]

332 вопросов

3
голосов
4ответов
244 просмотров

Does a Unittest has to have an Assertion like "assertEquals(..)"

I have a little JUnit-Test that export an Object to the FileSystem. In the first place my test looked like this public void exportTest { //...creating a list with some objects to export... JAXBService service = new JAXBService(); service.exportList(list, "output.xml"); } Usually m...

1
голосов
3ответов
939 просмотров

Source code is in JDK 1.4 and JUnit test cases in JDK 1.5

I am working on a project that is using JDK 1.4 and I am planning to write JUnit test cases in JDK 1.5 for several reasons like: I wanna explore JDK 1.5 to use Mocking frameworks more efficiently. Is it a good idea to do so?? (I've created two projects in Eclipse and am trying this)

11
голосов
8ответов
12587 просмотров

Is it possible to ignore certain unit tests?

I'm currently working on a project which uses JUnit4 extensively throughout all the modules. We're using Maven2 to build the project and Hudson for continuous integration. The project is built and run under Java 1.5. We've recently added quite a large raft of unit tests which are needed at times...

4
голосов
1ответов
5453 просмотров

Run Jettys ServletTester within JUnit test

I'm trying to run Jettys ServletTester in my JUnit test. I created a simple HelloServlet first to test the setup, but I get an IllegalAccessException when I try to request the servlet. Here is what I have so far: My unit test @Before public void setUp() throws Exception { tester = new Servl...

15
голосов
6ответов
8145 просмотров

Easiest way to unit test SWT and Swing apps in a headless environment?

I'm looking to unit test some SWT and Swing code for a project I'm working on and the tests run fine as long as I'm running them from eclipse. As soon as I run them in my hudson environment it fails since hudson runs the tests in headless mode. What's the best way of doing this? Open source so...

2
голосов
1ответов
222 просмотров

Spurious ^G (BELL) characters in JUnit log making CruiseControl barf

I have a CruiseControl build server running a large number of projects. On one of them I have recently noticed that only one of the two test suites are present in the build report (but failures in the other one still cause the build to fail). Further investigation showed that the XML output file...

6
голосов
2ответов
6236 просмотров

How to run all JUnit test cases from NetBeans?

I have created several files with unit tests on existing classes in NetBeans project. I used menu "File/New file/JUnit/Test for Existing Class" to create test files. I can run one file with unit tests by right click on it and select "Run File". But I want to run all files with unit tests. How c...

2
голосов
3ответов
1778 просмотров

Writing Unittest for generic classes... best approach?

I'm supposed to write unit tests for a project whose code another colleague has written. He created a generic list class. Now i'm thinking about, the best way to create the unittests for the class and how to avoid much repetitive code. The List class can be instaniated with String, Integer and so...

0
голосов
2ответов
5019 просмотров

MockEJB - JUnit Mockito - cannot rebind a mock EJB on second unit test

Hi I have a question related to MockEJB. I need to write unit tests to test a code that is calling a EJB. I use Mockito to write a mock for the EJB, and MockEJB to simulate the JNDI context. My tests look like this : @Test public void test1() throws Exception { // create a mock instance N...

24
голосов
5ответов
61452 просмотров

Does JUnit support properties files for tests?

I have JUnit tests that need to run in various different staging environments. Each of the environments have different login credentials or other aspects that are specific to that environment. My plan is to pass an environment variable into the VM to indicate which environment to use. Then use th...

2
голосов
4ответов
5452 просмотров

assertArrayEquals(Object[] o1, Object[] o2) cannot be found

My setup: Netbeans 6.7 Java6 JUnit 4.5 added as the Test libraries When I try to pass in two class arrays (cast as Object[]) I get the error "cannot find symbol" and my test case will not compile. I do not have an issue with the other assert statements, and as I said I am using the JUn...

47
голосов
6ответов
40981 просмотров

JUnit: @Before only for some test methods?

I have some common set up code that I've factored out to a method marked with @Before. However, it is not necessary for all this code to run for every single test. Is there a way to mark it so the @Before method only runs before certain tests?

16
голосов
3ответов
19691 просмотров

How do I test with DBUnit with plain JDBC and HSQLDB without facing a NoSuchTableException?

I am trying to use DBUnit with plain JDBC and HSQLDB, and can't quite get it to work -- even though I've used DBUnit with Hibernate earlier with great success. Here's the code: import java.sql.PreparedStatement; import org.dbunit.IDatabaseTester; import org.dbunit.JdbcDatabaseTester; import org...

1
голосов
3ответов
1207 просмотров

Can I run JUnit 4 to test Scala code from the command line?

If so, how? I haven't come across the proper incantation yet. If not, what's the best approach to unit-testing Scala code from the command line? (I'm a troglodyte; I use IDEs when I have to, but I prefer to play around using Emacs and command-line tools.)

5
голосов
4ответов
12813 просмотров

Spring / JTA / JPA unit test : Rollback not working

I am trying to test an entity EJB3 with Spring. The EJB itself does not uses Spring and I would like to keep duplications of the production JPA configuration minimal (ie not duplicating persistence.xml for exemple). My unit tests seems to work but even though my unit tests should be transaction...

25
голосов
3ответов
30659 просмотров

Easy way to compare ArrayLists for equality using JUnit?

What is an easy way to compare ArrayLists for equality using JUnit? Do I need to implement the equality interface? Or is there a simple JUnit method that makes it easier?

10
голосов
15ответов
1029 просмотров

How much unit testing is a good thing?

(No "related questions" seem to nail this, so here goes.) I work on production code. Arguing for anything that isn't visible to the user is hard to do, sometimes. If sales can't see it, it's an external cost to them, and they'll argue against it unless there's a great reason not to. How much ...

4
голосов
1ответов
1053 просмотров

Suspend on uncaught runtime exceptions in Eclipse Junit test runner

Eclipse is not suspending on an uncaught runtime exception during debugging of a Junit test. I've tried: JRE 1.6 update 15 and 16 Eclipse 3.5.0 and Eclipse 3.4.2 Checked "Suspend on uncaught exception" for the exception and all runtime exceptions Checked "Keep JUnit running after a test run whe...

9
голосов
2ответов
25209 просмотров

Debugging breakpoints on JUnit test in Eclipse are not working

I am trying to debug a junit test in eclipse but my breakpoints are not firing (unless they are on the first or second line). I've tried deleting and recreating all breakpoints in the workspace, cleaning the project, creating a new debug configuration, and running the test method individually an...

1
голосов
6ответов
506 просмотров

Small java project growing (maven and junit)

I'm working on a growing java project and I'm probably going to cooperate with somebody else to improve some features. I'd like to use some tools to improve the quality of my work keeping in mind that: I don't have too much time to spend on this project it's a small project but it's really imp...

1
голосов
4ответов
2878 просмотров

Different JUnit-result starting from Eclipse vs. mvn test

I've got a JUnit-test which is successfull when starting with mvn test but fails when starting from Eclipse (see stack trace below). What I'm trying to do is inserting new elements into the database with entityManager.persist() and entityManager.flush() (when calling flush, I get the error). My ...

11
голосов
2ответов
23186 просмотров

Proper way to autowire a Hibernate Session in a Spring Transaction JUnit test

This question is similar to a previous one. I am trying to @Autowire a Hibernate Session in one of my Spring-JUnit-Transactional tests but I am getting this exception: java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transact...

1
голосов
1ответов
5492 просмотров

easymock - matcher and multiple calls

Below is a test I have knocked up that uses its own matcher. I know in this case I could use a standard matcher but in my real code I need a more complicated one. The test passes - tick VG. The issue is that there appears to be an extra call to IArgumentMatcher.matches() method that returns fals...

2
голосов
5ответов
161 просмотров

Alternatives to backdooring java access when unit testing

I'm trying to unit test a class with a number of private methods. Each of the private methods can be rather extensive. I can either make the method package scoped (which causes a warning), or I can use the code below to test it: Method method = instance.getClass().getDeclaredMethod("methodName"...

5
голосов
1ответов
5592 просмотров

Failed web service unit tests behind a proxy in Eclipse

I have a problem executing unit tests in Eclipse behind a proxy, as the classes used by the unit tests call some web services, which are behind a proxy. In Tomcat I can of course specify a proxy to be used, but when I run unit tests directly from Eclipse, the proxy configuration of Eclipse seems ...

1
голосов
2ответов
5254 просмотров

How can i use JUnit in Servlet and JSP?

I am writing a web application which should be tested with JUnit framework. So please suggest me how we can use JUnit in Jsp and servlet and also how to generate test case reports using Ant?? Thanks in advance Why cant we use Cactus? I have heard about that and what it differs from other test ca...

2
голосов
3ответов
3811 просмотров

Running Eclipse Plug-in tests in non-ui thread

How do I run a Eclipse JUnit plug-in test in a non-ui thread when running the tests from the command-line? In the launch configuration dialog I can uncheck the checkbox "Run in UI thread", but how do I do that when running plug-in tests on the command-line? EDIT: It seems as if org.eclipse.pde.j...

126
голосов
11ответов
99983 просмотров

Easy way of running the same junit test over and over?

Like the title says, I'm looking for some simple way to run JUnit 4.x tests several times in a row automatically using Eclipse. An example would be running the same test 10 times in a row and reporting back the result. We already have a complex way of doing this but I'm looking for a simple way...

6
голосов
4ответов
4676 просмотров

Unit Testing an EJB

I'm looking for a way to apply TDD to Session Beans. can anyone provide advices and links on how to unit test them ? how to use JUnit to do so ? P.S : I'm new to Test Driven Development and Session Beans. I'm using EJB v2.

3
голосов
2ответов
1330 просмотров

How to generate JUnit sources using maven-gunit-plugin

I have maven configured to run gunit (an ANTLR grammar unit testing tool) through the maven-gunit-plugin. gunit, however, has two different modes. The first mode causes gunit to act as an interpreter, reading through the *.gunit (or *.testsuite) file, interpreting it, and displaying the results...