junit 1 « junit « Java Testing Q&A

Home
Java Testing Q&A
1.Development
2.FindBugs
3.HTMLUnit
4.hudson
5.junit
6.performance
7.plugin
8.profile
9.selenium
10.Tools
11.unit test
Java Testing Q&A » junit » junit 1 

1. Using different classloaders for different JUnit tests?    stackoverflow.com

I have a Singleton/Factory object that I'd like to write a JUnit test for. The Factory method decides which implementing class to instantiate based upon a classname in a properties file ...

2. Junit output and OutOfMemoryError    stackoverflow.com

I'm running some JUnit tests on my applications. Every test has a for loop calling respective method 10000 times. The tested methods produce a lot of log. These logs are also automatically ...

3. Is there a Java unit-test framework that auto-tests getters and setters?    stackoverflow.com

There is a well-known debate in Java (and other communities, I'm sure) whether or not trivial getter/setter methods should be tested. Usually, this is with respect to code coverage. Let's ...

4. Is there a JUnit TestRunner for running groups of tests?    stackoverflow.com

I am currently using JUnit 4 and have a need to divide my tests into groups that can be run selectively in any combination. I know TestNG has a feature to ...

5. Can I make JUnit more verbose?    stackoverflow.com

I'd like to have it yell hooray whenever an assert statement succeeds, or at the very least have it display the number of successful assert statements that were encountered. I'm using JUnit4. Any ...

6. Automatic JUnit on SVN checkin    stackoverflow.com

I'm using IntelliJ-Idea to write Java daemons. We use JUnit to unit test our code and want to have automated runs on check-in to subversion. Are there any tools available that can ...

7. Best way to automagically migrate tests from JUnit 3 to JUnit 4?    stackoverflow.com

I have a bunch of JUnit 3 classes which extend TestCase and would like to automatically migrate them to be JUnit4 tests with annotations such as @Before, @After, @Test, etc.
Any tool ...

8. Is running tests with JUnit 3.x vs JUnit 4.x still a best practice?    stackoverflow.com

I haven't looked at this in a while, but if I recall correctly both ant and maven still rely on JUnit 3 for unit tests (as of maven 2.09 the default ...

9. Runinng SQL script from JUnit    stackoverflow.com

In the setup method to a JUnit test case I'm working on I need it to run a sql script on my database before each test case, and then a rollback ...

10. Should @Entity Pojos be tested?    stackoverflow.com

I don't know if I should test my @Entity-annotated Pojos. After all, there are mainly just generated getters/setters. Should I test them? When it comes to testing DAOs I'm using all those ...

11. JUnit test with dynamic number of tests    stackoverflow.com

In our project I have several JUnit tests that e.g. take every file from a directory and run a test on it. If I implement a testEveryFileInDirectory method in ...

12. JUnit's @Ignore    stackoverflow.com

I wonder if it is a good practice to use JUnit's @Ignore. And how people are using it? I came up with the following use case: Let's say I am developing ...

13. Setting up Mobile JUnit tests to run under JUnit    stackoverflow.com

I'm using Mobile JUnit, released by Sony Ericsson for unit testing for my J2ME project. I read in the documentation that one can run the tests under regular junit with the ...

14. Running junit tests in parallel?    stackoverflow.com

I'm using junit 4.4 and maven and I have a large number of long-running integration tests. When it comes to parallellizing test suites there are a few solutions that allow me to ...

15. Junit4 Test Suites    stackoverflow.com

How do I create test suites with Junit4? All the documentation I've seen doesn't seem to be working for me? And if I use the eclipse wizard it doesn't give ...

16. Get name of currently executing test in JUnit 4    stackoverflow.com

In JUnit 3, I could get the name of the currently running test like this:

public class MyTest extends TestCase
{
    public void testSomething()
    {
   ...

17. JUnit produces strange AssertionFailedError    stackoverflow.com

I am currently using JUnit 4.4 and Java 1.6.x. And after a recent code fix, we started getting this AssertionFailedError in my JUnit tests on the method: UtilityTest.testParseDate(4t): Mon Jan 15 09:26:07 ...

18. Generating JUnit Testcases    stackoverflow.com

Our application depends on numerous resources that are provided by another system. To ensure the existence of those resources, we currently have a JUnit test case (probably more an integration test), that ...

19. How to use Junit to test asynchronous processes    stackoverflow.com

How do you test methods that fire asynchronous processes with Junit? I don't know how to make my test wait for the process to end (it is not exactly a unit test, ...

20. Change test name of parameterized tests?    stackoverflow.com

Is there a way to set my own custom test case name when using Parameterized tests in Junit4? I'd like to change the default "[Test class].runTest[n]" to something meaningful...

21. JUnit tests for POJOs    stackoverflow.com

I work on a project where we have to create unit tests for all of our simple beans (POJOs). Is there any point to creating a unit test for POJOs ...

22. Why can't java find the JUnit framework?    stackoverflow.com

I am trying to get a test class compiling with JUnit, and I can't figure out why it will not compile. I have the following lines at the top of my class:

import ...

23. Where should I put my JUnit tests?    stackoverflow.com

I've got 2 questions about organising Unit tests.

  1. Do I have to put test to the same package as tested class, or can I organise tests in different packages? For example if I ...

24. Grouping JUnit tests    stackoverflow.com

Is there any way to group tests in JUnit, so that I can run only some groups? Or is it possible to annotate some tests and then globally disable them? I'm using JUnit ...

25. JUnit theory for hashCode/equals contract    stackoverflow.com

The following class serve as generic tester for equals/hashCode contract. It is a part of a home grown testing framework.

  • What do you think about?
  • How can I (strong) test this class?
  • It ...

26. JUnit Max Equivalent Tool for Visual Studio    stackoverflow.com

I have been trying to find a tool similar to JUnit Max for Visual Studio. Preferably, the tool would work with Visual Studio 2008 Professional and NUnit. For those who are ...

27. Solution for Parameterized Tests    stackoverflow.com

I'm familiar with the use of Parameterized tests in JUnit, e.g: http://junit.org/apidocs/org/junit/runners/Parameterized.html but I wondered whether there were any alternative (possibly better) approaches to externally defined test data. I don't ...

28. Why must jUnit's fixtureSetup be static?    stackoverflow.com

I marked a method with jUnit's @BeforeClass annotation, and got this exception saying it must be static. What's the rationale? This forces all my init to be on static fields, for ...

29. C/C++ testing framework (like JUnit for java)    stackoverflow.com

Been hitting my head on the wall before as I don't make any test classes while using c/c++ (but instead have a lot of print methods). What is the most used method ...

30. Should the JUnit message state the condition of success or failure?    stackoverflow.com

I can write an assertion message one of two ways. Stating success:

assertEquals( "objects should be identical", expected, actual );
Or stating the condition of being broken:
assertEquals( "objects aren't identical", expected, actual ...

31. JUnit test for System.out.println()    stackoverflow.com

I need to write JUnit tests for an old application that's poorly designed and is writing a lot of error messages to standard output. When the getResponse(String request) method behaves correctly ...

32. 'new' modifier in Java    stackoverflow.com

Is there an equivalent to C#'s 'new' modifier in Java? I'd like to use it for unit tests - every init() method should be marked final and annotated with @Before. ...

33. How to best test Java code?    stackoverflow.com

I have been working on a comparatively large system on my own, and it's my first time working on a large system(dealing with 200+ channels of information simultaneously). I know how ...

34. JUnit expected tag not working as expected    stackoverflow.com

I have the following test case in eclipse, using JUnit 4 which is refusing to pass. What could be wrong?

@Test(expected = IllegalArgumentException.class)
public void testIAE() {
    throw new IllegalArgumentException();
}
This ...

35. JUnit two variables iterating respective value sets, create test functions    stackoverflow.com

Checking function takes two arguments, I want to have a testcase for each element of the cartesian product of the respective domains, but without manually writing all the test cases like ...

36. Junit throw warning while still passing test    stackoverflow.com

I'm working on a project at the moment that we're using junit to test, but as its still fairly early stages a lot of features aren't yet implemented, though they already ...

37. How can I make my JUnit tests run in random order?    stackoverflow.com

I have the classical structure for tests, I have a test suite of different suites like DatabaseTests, UnitTests etc. Sometimes those suites contains other suites like SlowDatabaseTests, FastDatabaseTests etc. What I want ...

38. How to generate JUnit sources using maven-gunit-plugin    stackoverflow.com

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 ...

39. assertArrayEquals(Object[] o1, Object[] o2) cannot be found    stackoverflow.com

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 ...

40. Junit REST tests?    stackoverflow.com

I am using Struts2, Spring 2 and Junit 4.5. My main question is, whether even to test REST calls? Because, basically this are only calls to business logic and they don't have ...

41. Re-running failed and not-run tests    stackoverflow.com

Let me describe a simple use-case: Running all tests in our project may take up to 10 minutes. Sometimes I see an obvious bug in my code after the first failed test, so ...

42. Compare Date objects with different levels of precision    stackoverflow.com

I have a JUnit test that fails because the milliseconds are different. In this case I don't care about the milliseconds. How can I change the precision of the ...

43. CruiseControl JUnit test results show all zeroes    stackoverflow.com

I've got JUnit hooked up with CruiseControl and unit tests are being executed & logs imported, but CruiseControl shows the following output:

nz.co.picksend.core.tests.nz.co.picksend.core.dal.FilterTests 
Tests: 0, Failures: 0, Errors: 0, Duration: 0.0
nz.co.picksend.core.tests.nz.co.picksend.core.dal.ModelObjectRegistryTests 
Tests: ...

44. Conditionally ignoring tests in JUnit 4    stackoverflow.com

OK, so the @Ignore annotation is good for marking that a test case shouldn't be run. However, sometimes I want to ignore a test based on runtime information. An example might ...

45. need suggestions on getting started with Junit    stackoverflow.com

I have not used Junit before and have not done unit testing automatically. Scenario: We are changing our backend DAO's from Sql Server to Oracle. So on the DB side all ...

46. JUnit Result Aggregation    stackoverflow.com

I'm familiar with aggregating junit test results within a single build, but are there any tools that let you aggregate results across different builds? I'd like to discover which tests failed most ...

47. How to instantiate a shared resource in JUnit    stackoverflow.com

I noticed that jUnit runs the constructor of my test class for each method being tested. Here's an example:


public class TestTest {
    protected BigUglyResource bur;
   ...

48. Should JUnit tests be javadocced?    stackoverflow.com

I have a number of JUnit test cases that are currently not documented with Javadoc comments. The rest of my code is documented, but I'm wondering if it's even worth the effort ...

49. Junit import using * wildcard    stackoverflow.com

I've noticed that when importing JUnit, the * wildcard doesn't always work.
e.g. for the annotation @Test you must import org.junit.Test since org.junit.* doesn't recognize the annotation. Is there a reason for this, ...

50. Data-driven tests with jUnit    stackoverflow.com

What do you use for writing data-driven tests in jUnit? (My definition of) a data-driven test is a test that reads data from some external source (file, database, ...), executes one test ...

51. JUnit: pause for user input    stackoverflow.com

I'm learning JUnit. Since my app includes graphical output, I want the ability to eyeball the output and manually pass or fail the test based on what I see. It should ...

52. Upgrading to JUnit4 and keeping legacy JUnit 3 tests and test suites by running them together    stackoverflow.com

I was surprised not to find the answer so far. If I am missing something basic I will be more than happy to know that. There is a large legacy code base ...

53. Subclassing a test subject for Junit testing    stackoverflow.com

I want to test validation logic in a legacy class. The class uses a method to load effective dates from a config file. I have written a subclass of the class ...

54. How do I use the Antlr generated junit file made by translating a gunit file    stackoverflow.com

I am trying to make unit tests for multiple return values in Antlr. I have regular unit tests working using gunit. However, I am not too sure what to do with ...

55. Remote JUNIT for functional testing    stackoverflow.com

I would like to execute JUnit on a remote machine hosting a JVM embedded and linked to a C application through JNI. This JVM has state and access to live external ...

56. JUnit 4 @BeforeClass & @AfterClass when using Suites    stackoverflow.com

When using this approach below, by setting up the jUnit with Suites. We got the problem when all @BeforeClass in every Testclass will be executed before any tests starts to execute. (For ...

57. JUnit Tests - what do i test?    stackoverflow.com

If I have a basic accessor method that returns an ArrayList What exactly would i test for it? I am very inexperienced when it comes to testing.

58. JUnit Return int value    stackoverflow.com

My Junit test should check that the number being returned is the same as the list size if my test was as follows would this be coded properly, i feel it isnt ...

59. JUnit Test Compiling    stackoverflow.com

I would like to compile JUnit from windows command line. I have a project that contains many different packages. I can compile and run this project from the command line. However, I ...

60. javadoc cannot find org.junit.Test    stackoverflow.com

When I run javadoc on my java source code, I get this error for th Junit test class:

[javadoc] /mypath/TestStuff.class: warning: Cannot find annotation method 'expected()' in type 'org.junit.Test': class file for ...

61. Different Singleton instances with JUnit tests    stackoverflow.com

I have a standalone singleton which successfully passes the test. But with a group of tests this fails since once a singleton is defined it does not allow to reset the ...

62. How can I make JUnit be quiet?    stackoverflow.com

When I run JUnit tests failures cause very large stack traces that don't really provide much information. I would like to be able to just see the failing assert statement, so ...

63. Example of standalone Apache Qpid (amqp) Junit Test    stackoverflow.com

Does anyone have an example of using Apache Qpid within a standalone junit test. Ideally I want to be able to create a queue on the fly which I can put/get msgs ...

64. How to run all tests belonging to a certain Category in JUnit 4    stackoverflow.com

JUnit 4.8 contains a nice new feature called "Categories" that allows you to group certain kinds of tests together. This is very useful, e.g. to have separate test runs for slow ...

65. Surefire is not picking up Junit 4 tests    stackoverflow.com

I cannot get Maven Surefire to execute my JUnit 4 tests even after I tried all the advices from another post. My POM:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>maven-test</groupId>
  <artifactId>maven-test</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  ...

66. Testing approach - DB, Junit    stackoverflow.com

i would like to ask you about writting tests which are connected with data from database. In my opinion the best way is to have a diffrent DB schema with correct ...

67. Compare two JSON objects in Java    stackoverflow.com

I'm looking for a JSON paring library that supports comparing two JSON objects ignoring child order, specifically for unit testing JSON returning from a web service against an expected value. Do any ...

68. How can I split abstract testcases in JUnit?    stackoverflow.com

I have an abstract testcase "AbstractATest" for an interface "A". It has several test methods (@Test) and one abstract method:

protected abstract A unit();
which provides the unit under testing. No i have ...

69. Ending a JUnit Test    stackoverflow.com

I have a "black box" of code that contains many threads. There is no method to "kill" the black box threads that I have found. I am passing data into the ...

70. How can I find out if code is running inside a JUnit test or not?    stackoverflow.com

In my code I need to do certain fixes only when it is run inside a JUnit test. How can I find out if code is running inside a JUnit test ...

71. junit test suites    stackoverflow.com

I have a script(test.bat) that allows me to launch one java test by command line : -java -cp() org.junit.runner.JUnitCore package.Class Now I want to do the same for several java tests ? how could ...

72. junit4 functions    stackoverflow.com

how to create generic functions that could be called from each java test? In my function startappli I have :

public class startappli{

public void testMain (String[] args) 
 {

  String[] ...

73. how to understand @Test & @BeforeClass?    stackoverflow.com

I am beginning with JUnit and do not understand the annotations @Test and @BeforeClass.
I have the following code:

public class Toto { 
@BeforeClass
    public static void setupOnce() {
  ...

74. Trying to write junit test, missing some basics    stackoverflow.com

When I try to use assertNotLesser or assertNotGreater I get compile error .. and eclipse suggest me to create a new method called like this .. http://junit-addons.sourceforge.net/junitx/framework/ComparableAssert.html I ...

75. Verify XHTML is valid in a JUnit test?    stackoverflow.com

I have a Spring controller that returns XHTML, what's the easiest way to setup a JUnit test that verifies that the XHTML is valid? I'd also like to verify certain ...

76. how to test this portion of code    stackoverflow.com

Hello I'm writting junit test how can I test this method .. this is only part of this method :

public MyClass{

public void myMethod(){
List<myObject> list = readData();
}
}
How will I make the test ...

77. JSON schema validation using java    stackoverflow.com

I'm writing some acceptance tests for a java webapp that returns JSON objects. I would like to verify that the JSON returned validates against a schema. Can anyone suggest any tools ...

78. Delete or comment out non-working JUnit tests?    stackoverflow.com

I'm currently building a CI build script for a legacy application. There are sporadic JUnit tests available and I will be integrating a JUnit execution of all tests into the ...

79. How to test whether a char is NOT in a string? (java, junit)    stackoverflow.com

As title says, im having trouble with my junit tests passing for checking if a character is not in a string and how to check if an empty string doesnt have ...

80. How can I reduce build time using a parallel build / parallelizing the tests?    stackoverflow.com

Simple question :) How can I reduce build time using a parallel build / parallelizing the tests? We're using TeamCity, JUnit, Fit, Selenium

81. JUnit - stop it from exiting on finish?    stackoverflow.com

Quick JUnit question. I'm running some unit tests that involve starting up the GUI and doing a load of stuff. I would like to see the results after the test to confirm ...

82. How do I run JUnit tests from inside my java application?    stackoverflow.com

Is it possible to run JUnit tests from inside my java application? Are there test frameworks I can use (such as JUnit.jar?), or am I force to find the test files, invoke ...

83. How to override/control the way the JVM gets the system date?    stackoverflow.com

How do you mock-up/trick the JVM to get a date other that the current system date? I have a set of tests in JUnit I don't want to change, but instead ...

84. Force IOException during file reading    stackoverflow.com

I have the piece of code that reads data from file. I want to force IOException in this code for testing purpose (I want to check if code throws correct custom ...

85. How can I specifiy JUnit test dependencies?    stackoverflow.com

Our toolkit has over 15000 JUnit tests, and many tests are known to fail if some other test fails. For example, if the method X.foo() uses functionality from Y.bar() ...

86. How to develop a Nightly Builder    stackoverflow.com

I was told to create a tool like a Nightly Builder for a JUnit project. It's a client-server project with oracle database.The tests are based on QTP. Also there is a ...

87. Why is my test not running    stackoverflow.com

Strangest thing happened my test was running ok and now its not anymore I didn't change the code at all here is the exception :

Class not found com.example.test
java.lang.ClassNotFoundException: com.example.test
   ...

88. Junit test that creates other tests    stackoverflow.com

Normally I would have one junit test that shows up in my integration server of choice as one test that passes or fails (in this case I use teamcity). What ...

89. Running a JUnit4 test - from a java program    stackoverflow.com

I was wondering how to run some JUnit4 test inside a java program. Basically - depending on some conditions during runtime I need to decide which test runner to use. Using ...

90. JUnitCore.runClasses doesn't print anything    stackoverflow.com

I have a test class that I'm trying to run from a main method with the folowing code :

Result r = org.junit.runner.JUnitCore.runClasses(TestReader.class);
when I examine the Result object I can see ...

91. Using JUnit as an acceptance test framework    stackoverflow.com

OK, so I work for a company who has openly adopted agile practices for development in recent years. Our unit tests and code quality are improving. One area we ...

92. Access POP3 account from JUnit tests    stackoverflow.com

I'm looking for a way to access a POP3 account while running a JUnit test. Does anyone know how to do that? I probably need some kind of library for POP3 ...

93. Basic jUnit Questions    stackoverflow.com

I was testing a String multiplier class with a multiply() method that takes 2 numbers as inputs (as String) and returns the result number (as String)

public String multiply(String num1, String ...

94. JUnit Rule TemporaryFolder    stackoverflow.com

I'm creating a TemporaryFolder using the @Rule annotation in JUnit 4.7. I've tried to create a new folder that is a child of the temp folder using tempFolder.newFolder("someFolder") in the @Before ...

95. How to handle ordering of @Rule's when they are dependant on each other    stackoverflow.com

I use embedded servers that run inside Junit test cases. Sometimes these servers require a working directory (for example the Apache Directory server). The new @Rule in Junit 4.7 can handle these ...

96. What java version is needed for JUnit 4.8    stackoverflow.com

I am trying to run JUnit test with a 1.5 JRE, but get the error Message:

java.lang.UnsupportedClassVersionError: Bad version number in .class file
When I switch to JRE 1.6 (actually a JDK but ...

97. Best testing framework?    stackoverflow.com

Is JUnit the best unit testing framwork? Which framework is best for new java projects?

98. JUnit Best Practice: Different Fixtures for each @Test    stackoverflow.com

I understand that there are @Before and @BeforeClass, which are used to define fixtures for the @Test's. But what should I use if I need different fixtures for each @Test?

  • Should I ...

99. Junit run not picking file src/test/resources. For file required by some dependency jar    stackoverflow.com

I m facing a issue where test/resource is not picked,but instead jar's main/resource is picked Scenario is like : Myproject src/test/resources--- have config.xml w which should be needed by abc.jar which is a dependecy ...

100. JUnit Custom Rules    stackoverflow.com

JUnit 4.7 introduced the concept of custom rules: http://www.infoq.com/news/2009/07/junit-4.7-rules There are a number of built in JUnit rules including TemporaryFolder which helps by clearing up folders after a test has been ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.