junit 3 « 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 3 

1. Guice injector in JUnit tests    stackoverflow.com

Using Guice, is it a good practice to get a new injector in each JUnit test class, as each test class should be independant?

2. JUnit examples to teach    stackoverflow.com

I need good examples of Junit tests for Java classes, to spend in training, anyone have suggestions of good examples?

3. Testing toString Junit    stackoverflow.com

i have a question about testi toString construct in a Java class: give a toString method:

public String toString()
{
    String accountString;
    NumberFormat money = NumberFormat.getCurrencyInstance();

  ...

4. Difference between JUnit Theories and Parameterized Tests    stackoverflow.com

What is the difference between a Theory and a Parameterized test? I'm not interested in implementation differences when creating the test classes, just when you would choose one over the other. ...

5. How to clean resource when I interrupt a JUnit4 test in debug mode?    stackoverflow.com

How do you manage resource clean up in JUnit4 (in a JUnitRunner / in a TestCase) when you interrupt the test in debug mode ? I use Selenium WebDriver by implementing JUnit ...

6. Paramterized Testing with Junit    stackoverflow.com

How can I test the following method with parameterized testing in Junit public class Math { static public int add(int a, int b) {
...

7. Globally setting a JUnit runner instead of @RunWith    stackoverflow.com

Without looking into JUnit source itself (my next step) is there an easy way to set the default Runner to be used with every test without having to set @RunWith on ...

8. java testing: accelerate time to test timeouts?    stackoverflow.com

I have an app that manages turns in a game, it's fairly complex and it has a lot of timers that generate timeouts.. since they interoperate a lot it's difficult to ...

9. Simple Junit configuration is not working    stackoverflow.com

I have some old code that I would like to test using Junit. After importing it into Eclipse it looks like this: project imported into Eclipse After this, I try to ...

10. Java JUnit Testing    stackoverflow.com

Chris has written a function called toBinary that has an input parameter of an integer number and returns a string that represents the binary equivalent. For example, if the function is ...

11. Integrating SoapUI with JUnit    stackoverflow.com

I am trying to integrate SoapUI into my preexisting JUnit tests. I have created a test in SoapUI 3.6.1. It works. My next step is to apply it to my ...

12. jUnit: How to filter tests found in multiple suites    stackoverflow.com

When jUnit runs a test suite containing multiple "sub suites", is it possible to filter tests found in different suites as to make them run only once? I'm working on a ...

13. jUnit how to use @Test(expected=...)    stackoverflow.com

I have this method

public String getNum(int x) throws Exception
{
    if(x == 0){
         throws new Exception("x cannot be 0");
   ...

14. Checking for deep equality in JUnit tests    stackoverflow.com

I am writing unit tests for objects that are cloned, serialized, and/or written to an XML file. In all three cases I would like to verify that the resulting object is ...

15. JUnit Testing I/O    stackoverflow.com

I have implemented two static void methods which create files and read files. And I want to test the methods but I don't know how to test methods which work with files. What ...

16. JUnit: using constructor instead of @Before    stackoverflow.com

I'm using JUnit 4. I can't see the difference between initializing in the constructor or using a dedicated init function annotated by @Before. Does this mean that I don't have to ...

17. How to group test data in a parameterized test?    stackoverflow.com

I'm working on an application which has a grid and only some points of the grid are considered valid. I need to test this extensively with all possible grid values or ...

18. Need help with testing with junit, please!    stackoverflow.com

I'm trying to write a test for the following method:

 public class Sort {

...
...
...

    public static String[][] findRanks(String[][] array, int indexOfPoints, int indexOfRank) {

     ...

19. Dealing with System.exit(0) in JUnit tests    stackoverflow.com

I am implementing some tests for an existing Java Swing application, so that I can safely refactor and extend the code without breaking anything. I started with some unit tests in ...

20. Using unitils/dbMaintain to maintain database, how to exclude scripts from being run?    stackoverflow.com

I am using unitils (and its dbMaintain module) to maintain the state of my local database. dbMaintain has an option to exclude/include scripts based on a qualifier. See

21. how to configure java junit with Teamcity?    stackoverflow.com

Can somebody please tell me how to integrate java JUnit with TeamCity?

22. Testing API which returns multiple values with JUnit    stackoverflow.com

I would like to test an API, which received one argument and returns a set. The test invokes the API with an argument and checks if the returned set contains ...

23. Just got my first job in industry - what do I need to know?    stackoverflow.com

Tomorrow, I will be taking up my first job as a software engineer. I am doing an internship as a Software Test Engineer doing black box and white box testing. ...

24. JUnit 4 base functionality    stackoverflow.com

What is the proper way with JUnit 4 to create test cases to use common functionality: e.g. setup that is common to several unit test classes? What I did was ...

25. JUnit: Check that a collection only contains objects of a certain type    stackoverflow.com

Say I have a method that returns a collection of Animals. In one case I want to check that this method contains exactly 7 Dogs. Checking the number isn't a problem, ...

26. assertArrayEquals testing    stackoverflow.com

I have this problem in testing assertArrayEquals in JUnit as I am not sure how it works. I created a method so I can understand it but its not working. Can ...

27. Configuring system tests in junit    stackoverflow.com

We currently have a dedicated tool for running system tests on our web services, but I've been thinking of re-writing it to be hostable within jUnit4. This would give us several advantages, ...

28. How can I write a JUnit test for a JNI call that crashes?    stackoverflow.com

I'm working on fixing a JNI call that's crashing at the moment. Striving to be a good TDD practitioner, I've created a JUnit test to replicate the problem, which it ...

29. how to set a flag / variable in xslt to enter if again (related to converting to Junit format)    stackoverflow.com

I am reading an external log file via xslt, and i want to find a certain line. Once i find it, i want to print all the lines until i hit another ...

30. unexpected token while I'm trying to generate the following code    stackoverflow.com

public Integer getCancelStatusForMacId (String macAddress){

        if (logger.isDebugEnabled()) {
            logger.debug("getLinkIdByPartnerSiteId Begin ");
   ...

32. retrieve Junit test expected result    stackoverflow.com

I'm writing Junit test cases for a bunch of classes; each of them has a handful of method to test. The classes Im about to test look like the following.

class A{
 ...

33. compiler.FunctionTable.installFunction - NoSuchMethodError    stackoverflow.com

I am trying to run a very simple functional test using HTMLUnit:

public void testHomePage () throws Exception{
    final WebClient webClient = new WebClient();
    assertEquals(1,1);
  ...

34. JUnit: testing an object is not in a list    stackoverflow.com

In JUnit tests, I need to test that a given object (not the reference, but the attributes of the object) is not in a list. What's the best way to do ...

35. What can terminate a test in JUnit    stackoverflow.com

I'm trying to use findbugs as a library for my program (but the problem is not strictly related to findbugs). I've wrote several tests to configure and call some ...

36. Junit and messageboxes    stackoverflow.com

I am new to JUnit and I got a sample java project in which I need to write unit tests for all the methods. Unfortunately the code is poorly designed and some ...

37. JUnit - Oracle Database and StaleConnections    stackoverflow.com

I was wondering is there any way in Java to force a stale connection? We have some logic that determines if a sqlexception received is actually a Stale Connection - if it ...

38. JUnit Testing Cassandra with embedded server    stackoverflow.com

What is the best approach to write unit tests for code that persists data to nosql data store, in our case cassandra? => We are using embedded server approach using a utility ...

39. Best practices for keeping JUnit testing up to date    stackoverflow.com

I have been given the tasks of re-organization and documentation of a bunch of JUnit tests, about 1800, that have very little documentation and are not organized very well. Does ...

40. Alternatives to JUnit    stackoverflow.com

Are there any alternatives to JUnit? I have a head unit running a proprietary stripped down version of JRE 1.4.2, and JUnit is incompatible with this implementation.

41. how to test file system related behavior and delete the created dir    stackoverflow.com

My program needs to interact to a directory (with a hierarchical structure) a lot and I need to test it. Therefore, I need to create a directory (and then create sub ...

42. How to deal with interdependent JUnit tests?    stackoverflow.com

I have a question about JUnit testing. Our JUnit suite is testing various functions that we wrote that interact with our memory system. The way our system was designed, requires it to be ...

43. JUnit Test Indexing    stackoverflow.com

I'm trying to come up with an efficient way to index my JUnit test, and hopefully come up with some automated way to do it. Right now, I've got a JUnit Text ...

44. The differences between JUnit 3 and JUnit 4    stackoverflow.com

Could someone describe in a few words what the main differences between JUnit 3 and 4 are? Thanks in advance...

45. JUnit Testing private variables?    stackoverflow.com

I have been assigned the task of unit testing a class that I never worked directly on with JUnit, and am strictly forbidden to change the code in the package. ...

46. How to write junit tests for interfaces?    stackoverflow.com

What is the best way to write junit tests for interfaces so they can be used for the concrete implementing classes? e.g. You have this interface and implementing classes:

public interface MyInterface {
 ...

47. Is there a way to access private plsql procedures for testing purposes?    stackoverflow.com

I'm working on a project with a lot of plsql code and would like to add more specific unit-tests to our codebase. Some of the procedures/functions I like to test aren't ...

48. Different teardown for each @Test in jUnit    stackoverflow.com

Is there way to define a different teardown for each @Test in jUnit?

49. Separate DataPoints into groups?    stackoverflow.com

Is it possible to group DataPoints by something other than their type? For example, suppose I have a Theory that I want to test, using "age" and "weight" as parameters:

@Theory
public void testSomething(int ...

50. How can I add a Java environment variable during JUnit Test Execution    stackoverflow.com

I need to define a system property for my JUnit tests. I've tried various steps to pass the name/value pair into gradle. (I've tried Milestone-3 and 4). None of these approaches ...

51. How could i get a Testname / Test status in JUnit    stackoverflow.com

I am new to JUnit . I am working on the ways to get a output like classname / function name / status / description. I figured that there is no other ...

52. Enforce jUnit tests cover the whole interface    stackoverflow.com

How can I enforce that my test class covers a particular interface? Also is there a convention for writing overloaded test methods, so the names are consistent (my current technique is ...

53. assumeTrue in JUnit4 is erring instead of ignoring tests    stackoverflow.com

I'm using JUnit 4 (junit-4.8.2.jar) to run tests on my Java project and am running into problems when using assumeTrue. I have this basic set up:

public class ClientTest extends TestCase ...

54. I got javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated on my JUnit test    stackoverflow.com

I am creating some unit tests for an app that uses a REST API. When I try to send a HttpPost request to the server URL (https://some.server.com), I got this:

javax.net.ssl.SSLPeerUnverifiedException: peer ...

55. Consolidate JUnits on to a single portal    stackoverflow.com

I would like to consolidate all my jUnits onto a single web portal (like fitnesse) and build them every night for a consolidated report. Are there any opensource tools available for ...

56. junit tearDownClass() vs tearDown()    stackoverflow.com

What is difference between tearDownClass() & tearDown() methods? Where can I find documentation for both. junit.org documentation of JUnit listed only tearDown() not tearDownClass(): ...

57. MockEJB fails when upgrade to jdk1.6    stackoverflow.com

We are in the process of upgrading our J2EE application from jdk1.4 to jdk1.6 along with moving to a different application server. Yes, lots of moving parts. However, I had written ...

58. Is it possible to exclude multiple categories in JUnit 4?    stackoverflow.com

I would like to do something like:

@RunWith(Categories.class)
@Categories.IncludeCategory(Small.class)
@Categories.ExcludeCategory({Manual.class, NonFunctional.class})
@Suite.SuiteClasses(AllTests.class)
public class SmallTests {
}
but ExcludeCategories accepts only one class, not an array of classes.

59. Using Emacs JDEE with JUnit    stackoverflow.com

I'm pulling my hair out getting JDEE set up. I've finally got the prj.el file to the point where I can run Ant tasks and I can do compiles of src .java ...

60. AssertNull should be used or AssertNotNull    stackoverflow.com

This is a pretty dumb question but my first time with unit testing so: lets say I have an object variable like obj and I want my unit test to Fail if ...

61. AssertionFailedError    stackoverflow.com

I am facing the following problem while running it using junit: All the methods are working fine except testValidatePanelistIDHwid. This is the new method that i have added in this class ...

62. Extending JUnit4    stackoverflow.com

I would like to run a series of integration tests against a system. I would like to ditch the boilerplate @Before and @After code that just involves getting and releasing a ...

63. Junit Tests returning as Unrooted Tests    stackoverflow.com

I've similar questions asked on this site, but this is a bit of a different scenario than what I have seen. We have a PC client execute JUnit 4 tests. However, we ...

64. can a junit testmethod have a argument?    stackoverflow.com

import java.util.regex.Pattern;

public class TestUI {
private static Pattern p = Pattern.compile("^[A-Za-z0-9()+-]+$");


public static void main(String[] args) {
// TODO Auto-generated method stub

//Test case1
    String[] str=test();

    System.out.println(str[0]+str.length);
match("Alphanumeric(Text)");
}


private static String[] ...

65. How do I pass an argument to a JUnit Test?    stackoverflow.com

I would like to pass arguments to my JUnit tests from run configurations. How do I reach to JUnits main method to access to those args? Anybody knows how to do ...

66. How run junit with parametrized constructor    stackoverflow.com

I have to run junit test from command line and one of the guy in the team created junit classes like below:

public Test extends TestCore
{
   String some;

   ...

67. Organizing JUnit tests    stackoverflow.com

In the past I would make a test suite per package, that would hold all of the tests in that package. then I would roll up all of the package test suites ...

68. How to insert input into System.in?    stackoverflow.com

I'm doing a simple assignment that reads user input from System.in, but then it suddenly occurred to me that the assignment requires me to create jUnit test cases to confirm that ...

69. Using JUnit to perform an insert    stackoverflow.com

I need to insert data into a table using JUnit tests. Is this possible? If so, how? Thanks!

70. jUnit, Testing the "new" reference    stackoverflow.com

Suppose you have a method like

public Something copy () {
  return new Something();
}
In your jUnit, you have
Something s1 = new Something();
Something s2 = s1.copy()
Other then
assertTrue (s1 != s2);
assertTrue (s2 ...

71. How does Emma work?    stackoverflow.com

For using Emma we'll first instrument the jar using Emma. During that time em metadata files will get generated and when you run the JUnit test cases over the instrumented jars ...

72. Using multiple @parameters for JUNIT4    stackoverflow.com

I am trying to write parameterize test in JUNIT4 and I don't know how to make multiple parameters for instance : @parameter1 {1,2,3,4} @test1 run test using @parameter1 @parameter2 {3,55,66,77} @test2 run test using @parameters2 Could anyone provide me with ...

73. How to attach a DataPoint with a Theory?    stackoverflow.com

@DataPoints public static final Integer[] input1={1,2};
@Theory
@Test
public void test1(int input1){

}

@DataPoints public static final Integer[] input2={3,4};
@Theory
@Test
public void test2(int input2 ){

}
I want that test1 runs with data set input1 - {1,2} and test2 runs ...

74. What is the standard for testing in Java?    stackoverflow.com

What apps would you use? Are there auto testing suites like autotest for ruby? What do you use and why? To be honest, I don't even know how to write ...

75. List jUnit Tests That Were Run    stackoverflow.com

Is there a way to get a list of the jUnit tests that were run for the purpose of including that list in a report? Rather than copying the 80 unit tests ...

76. How to make contributions to JUNIT open source    stackoverflow.com

How can one make contributions to JUnit or any other open source java framework in general? I am a entry level programmer and any suggestions are welcome.

77. xmldatasource in junit test    stackoverflow.com

How can we use xmldatasource in junit test? I am using spring and hibernate in my application I have created xmldatasource using Eclipse Database View. Thanks, Bhupendra Kalakoti

78. Ignore JUnit test    stackoverflow.com

I have a test and I want that it should not be launched what is the good practice : set Ignore inside test? @Deprecated? I would like to not launch it but ...

79. Writing first JUnit test    stackoverflow.com

So I've read the official JUnit docs, which contain a plethora of examples, but (as with many things) I have Eclipse fired up and I am writing my first JUnit test, ...

80. Is junit-addons compatible with Junit4.x?    stackoverflow.com

According to the SourceForge project page, junit-addons is compatible with Junit 3.7 and 3.8. Does anyone know if this will work with Junit4.x? If not, are there any alternative ...

81. Fundamentals of iostream and read/writeObject calls    stackoverflow.com

I am designing a java server to respond to multiple client requests. So the design basically has a server socket, accepts a client socket, creates a inputObjectStream and a outputObjectStream from ...

82. How to test an interpreter using JUnit?    stackoverflow.com

I am writing tests for an interpreter from some programming language in Java using JUnit framework. To this end I've created a large number of test cases most of them containing ...

83. how to troubleshoot intermittent junit test failures?    stackoverflow.com

I am dealing with a case where my tests pass or fail based on the order of declaration. This of-course points to not properly isolated tests. But I am stumped about ...

84. Junit good practices    stackoverflow.com

I have a code which retrieves few information from Database. For example if you pass person Id, method will return you person details like:
Name: XXX X XXX
Address: XXXXXXXXXXXXX XXXXX
Phone: ...

85. JUnit @Rule lifecycle interaction with @Before    stackoverflow.com

I have some JUnit tests that use the TemporaryFolder @Rule. They use the TemporaryFolder in a @Before method to perform some setup:

@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Before
public void init() {
  ...

86. Is it possible to run fitlibrary tests using the FitNesseSuite JUnit runner?    stackoverflow.com

I already run fitnesse suites outside of the fitnesse server using a test class of the form:

@RunWith(FitNesseSuite.class)
@Name("FitNesse.MyAcceptanceTestSuite")
@FitnesseDir("src/it/resources")
@OutputDir("target/fitnesse-results")
@DebugMode(true)
public class JavaFitNesseSuiteIT {
    //
}
I've managed to get fitlibrary running on my ...

87. Which one is better, object creation or simple expression evaluation?    stackoverflow.com

A little background, I'm hitting a situation where I haven't been able to enable assertions (asked here) and using a great solution like forceassertions is not possible for ...

88. Junit multiple threads    stackoverflow.com

I have a test case that provides arguments and executes the main method of a class. What would be the best approach using Junit to have multiple threads concurrenlty execute the ...

89. execute some code before any junit test will run    stackoverflow.com

Good day everyone, I tried searching, but failed to find the answer. I have a lot of unit tests files that basically execute the same @BeforeClass. They start jetty web server, add ...

90. Has JUnit4 begun supporting ordering of test? Is it intentional?    stackoverflow.com

A newbie to JUnit (in fact JUnit 4) and came across suite way of executing test

@RunWith(Suite.class)
@Suite.SuiteClasses(
        {        ...

91. testing Webseal without webseal    stackoverflow.com

I need to test SSO using Webseal. I'm not even close to being able to get access to the Webseal itself (client site installation). My JAVA code is very simple:

String userId = ...

92. How can I run JUnit tests under SCons?    stackoverflow.com

Seems like there's no answer on the internets. All I need is to concoct an SConstruct that does two things:

  • runs JUnit
  • produces reasonable output for CruiseControl to display

93. Simulate FlexContext and FlexSession in Junit test    stackoverflow.com

I am writing a Junit test that will test certain java classes. These classes heavily use the FlexContext and FlexSession and assume that all the requests are coming from the Flex ...

94. Cucumber running at multiple scenarios    stackoverflow.com

I have tried to follow this steps. But when I try to run multiple scenarios in the same file, my jUnit seems to be completely lost. It runs a ...

95. Sanity Check - Significant increase in the number of objects when using JUNIT    stackoverflow.com

I am using Junit for the first time in a project and I'm fascinated by the way it is forcing me to restructure my code. One thing ...

96. can I use a Junit Test as a precondition For another Junit Test    stackoverflow.com

The title pretty much says it all but I will clarify anyway. I have a jUnit test (lets call it T1) in which I use an assertion. For that assertion to be ...

97. JUnit test giving NullPointerException    stackoverflow.com

One of my JUnit tests is giving me a NullPointerException and I can't figure out why. This is the contents of the test class, PacketWrapperTest:

/**
 * Mock Node for Packet A.
 */
private ...

98. Functional Testing in Java    stackoverflow.com

I believe functional testing is testing of two or more modules together with the intent of finding defects, demonstrating that defects are not present, and verifying that the module performs its ...

99. junit custom runner implementation    stackoverflow.com

I am trying to customize a runner for junit. I am using the Extended runner given here: http://codehowtos.blogspot.com/2011/04/run-junit-test-repeatedly.html adding my own created Filter Runner's code, which extends Runner, to the ExtendedRunner ...

100. Unit-testing code with unpredictable external dependencies    stackoverflow.com

I am involved with a project which must, among other things, controlling various laboratory instruments (robots, readers, etc...) Most of these instruments are controlled either through DCOM-based drivers, the serial port, or ...

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.