class 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 » class 1 

1. What's the proper way to test a class with private methods using JUnit?    stackoverflow.com

How do I use JUnit to test a class that has internal private methods? It seems bad to change the access modifier for a method just to be able to run ...

2. JUnit can't find my class    stackoverflow.com

I am running JUnit through TextMate, and when I try to run my test cases I get this error

JUnit version 4.5
Could not find class: ProgTest

Time: 0.001

OK (0 tests)
Progtest.java can be found ...

3. Tips for speeding up build time on Linux using ANT, Javacc, JUnit and compiling Java classes    stackoverflow.com

We have a large codebase that takes approx 12 minutes on the developer machines to auto-generate some Java 5 classes using JavaCC and then compiles all the classes as well as ...

4. Parameterized test case classes in JUnit 3.x    stackoverflow.com

I have a JUnit 3.x TestCase which I would like to be able to parameterize. I'd like to parametrize the entire TestCase (including the fixture). However, the TestSuite.addTestSuite() method does not ...

5. differences between 2 JUnit Assert classes    stackoverflow.com

I've noticed that the JUnit framework contains 2 Assert classes (in different packages, obviously) and the methods on each appear to be very similar. Can anybody explain why this is? The classes ...

6. How to get Junit 4 to ignore a Base Test Class?    stackoverflow.com

I have a base class for many tests that has some helper methods they all need. It does not by itself have any tests on it, but JUnit (in eclipse) is invoking ...

7. Best Practice: Initialize JUnit class fields in setUp() or at declaration?    stackoverflow.com

Should I initialize class fields at declaration like this?

public class SomeTest extends TestCase
{
    private final List list = new ArrayList();

    public void testPopulateList()
   ...

8. JUnit: how to avoid "no runnable methods" in test utils classes    stackoverflow.com

I have switched to JUnit4.4 from JUnit3.8. I run my tests using ant, all my tests run successfully but test utility classes fail with "No runnable methods" error. The pattern I ...

9. JUnit: Could not find class    stackoverflow.com

I just installed JUnit but I can't get it to work:

C:\tools\junit4.6>java org.junit.runner.JUnitCore org.junit.tests.AllTests.
JUnit version 4.6
Could not find class: org.junit.tests.AllTests.

Time: 0

OK (0 tests)
This are my environment variables:
CLASSPATH=.;C:\Program Files\Java\jre1.5.0_11\lib\ext\QTJava.zip;c:\tools\junit4
.6\junit-4.6.jar;c:\tools\junit4.6\
JAVA_HOME=c:\Program Files\Java\jdk1.6.0_07
I just followed these ...

10. Junit SuiteClasses with a static list of classes    stackoverflow.com

SuiteClasses will work just fine with a list of classes like {Test1.class,Test2.class}, but when I try to generate a static list of classes, it says incompatible types: required java.lang.Class<?> but found ...

11. Lack of support base class in Junit4/Jmock2    stackoverflow.com

We're finally migrating our unit test code base from JUnit 3 to JUnit 4. We also make heavy use of JMock 2. With JUnit 3, JMock provides a useful base class ...

12. How to run external testcase(Class,junit) in java program?    stackoverflow.com

How to run external testcase(Class,junit) in java program?

13. Exclude individual JUnit Test methods without modifying the Test class?    stackoverflow.com

I'm currently re-using JUnit 4 tests from another project against my code. I obtain them directly from the other project's repository as part of my automated Ant build. This is great, ...

14. Is there a customizable class loading order using ant junit task?    stackoverflow.com

in our web-app project, we include some jar files. For patching some issues of one of the classes in a jar file, we changed the implemention of this class in a ...

15. Class teardown in junit 3?    stackoverflow.com

We have a lot of integration tests written using JUnit 3, though we're now running them with 4.4. A few of these have a need for a tearDown method that ...

16. How to test/design a class which has a private field that needs to be modified inside Junit testing?    stackoverflow.com

Suppose I have a class ClasswithPrivateState which has a private field that depends strictly on the current system state when the object is created. Currently, this field is initialized inside the ...

17. Applying one test to two separate classes    stackoverflow.com

I have two different classes that share a common interface. Although the functionality is the same they work very differently internally. So naturally I want to test them both.

The ...

18. JUnit: Enable assertions in class under test    stackoverflow.com

I've been bit a few times by Java assert statements that didn't fail in the JUnit test suite because assertions weren't enabled in JUnit's JVM instance. To be clear, these are ...

19. junit testing a class with shell scripting functionality under win32    stackoverflow.com

We have an API which is used in a class via an exposed interface. The API is meant for UNIX family and assumes, that every UNIX has /bin/sh. Thus when running ...

20. Java jUnit: Test suite code to run before any test classes    stackoverflow.com

I have a test suite class:

@RunWith(Suite.class)
@Suite.SuiteClasses({
    GameMasterTest.class,
    PlayerTest.class,
})
public class BananaTestSuite { 
What annotation do I need to use to make a function in this class ...

21. JUnit extend base class and have tests in that class being run    stackoverflow.com

I am using JUnit 3 and have a situation where often I have to test that an object is created correctly. My idea was to write a class MyTestBase as ...

22. jUnit ignore @Test methods from base class    stackoverflow.com

Let's say I have a test class called testFixtureA with serveral methods testA, testB, testC, etc, each with @Test annotation. Let's now say I subclass testFixtureA into class called testFixtureAB and ...

23. Remove Test code from java class    stackoverflow.com

Is there a way to strip the JUnit @Test code from my Java class. At the moment I embedded the test code in the same file as the source code to be ...

24. Junit 4 test suite and individual test classes    stackoverflow.com

I have a JUnit 4 test suite with BeforeClass and AfterClass methods that make a setup/teardown for the following test classes. What I need is to run the test classes also ...

25. junit4 test runner    stackoverflow.com

my java test do not compile, I run it and have : no junit tests could not find main class (specified in run-configuration)

26. Separation of JUnit classes into special test package?    stackoverflow.com

I am learning the concepts of Test-Driven Development through reading the Craftsman articles (click Craftsman under By Topic) recommended in an answer to my previous question, "Sample project ...

27. EasyMock Class Extension mock isn't mocking methods    stackoverflow.com

I've got this in mycode:

import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.reset;
import static org.easymock.classextension.EasyMock.verify;
...
mockMember = createMock(Member.class);
mockMember.incrPlayInPlay(200);
Because I want to tst that the method incrPlayInPlay is called. However, mockMember.incrPlayInPlay is actually calling the ...

28. Need help with developing a class for my JUnit test    stackoverflow.com

I have this JUnit test that I need help developing a Interface and Class for, here is the test:

Box b1 = new DefaultBox( "abc" ); Box b2 = new DefaultBox( "def" ...

29. JUnit: 4.8.1 "Could not find class"    stackoverflow.com

Ok, I am like other and new to jUnit and having a difficult time trying to get it working. I have searched the forum but the answers provided; I am just ...

30. Running JUnit test classes from another JUnit test class    stackoverflow.com

I have two classes that I am testing (let's call them ClassA and ClassB). Each has its own JUnit test class (testClassA and testClassB respectively). ClassA relies on ClassB for its normal ...

31. getPackage() returning null when my JUnit test is run from Ant    stackoverflow.com

I'm having problems running a JUnit test. It runs fine in Eclipse, but now I'm trying to run it from the command-line using Ant. The problem is that the following code ...

32. Junit 4 custom test class description    stackoverflow.com

I am using the @Parameterized annotation to run a test class over and over again against different test files. The problem is that in my IDE/build server the tests ...

33. How to write a jUnit test for this class?    stackoverflow.com

I would like to know what's the best approach to test the method "pushEvent()" in the following class with a jUnit test. My problem is, that the private method "callWebsite()" always ...

34. Junit before class ( non static )    stackoverflow.com

Are there any best practices to get Junit execute a function once in a test file , and it should also not be static. like @BeforeClass on non static function? Here is an ...

35. Javadoc in Junit test classes?    stackoverflow.com

Is it a best practice to put Javadoc comments in junit test classes and methods? Or is the idea that they should be so easy to read and simple that ...

36. Specifying an order to junit 4 tests at the Method level (not class level)    stackoverflow.com

I know this is bad practice, but it needs to be done, or I'll need to switch to testng. Is there a way, similar to JUnit 3's testSuite, to specify the ...

37. What is the correct terminology & best practice for common fixtures between test classes?    stackoverflow.com

I understand in Junit 4, @Before can be used to setup test fixtures for the test class's multiple test methods. However, in my system, there are common test objects i would like ...

38. How can I use jUnit to test a class that uses a singleton?    stackoverflow.com

I am developing a simulator for a machine. It reads a file in, stores it in a string (as a binary number) to an array that is supposed to simulate the ...

39. testing the class that returns the service using powermock?    stackoverflow.com

I want to test certain underlying services using powermock. but it is complicated. i would like to get your suggestion

public interface service{
  public void some_method(){
  }
}
public serviceclient implements service ...

40. Get Class name from within a method    stackoverflow.com

I would like to reference a Class's name within a method. In the following example, I would like TestSuite to be printed out. I can put CarsTestSuite.class.getName(), but I'd ...

41. How to test an anonymous inner class that calls a private method    stackoverflow.com

We have a bunch of classes that listen for events from the server and then respond to them. For example:

class EventManager {
    private Set<Event> cache = new HashSet<Event>();

 ...

42. How do I test local inner class methods in java?    stackoverflow.com

In many application I often have algorithms which make use of dedicated sub-algorithms (or simply well defined pieces of code). Till now, when I wrote the main algorithm, i created a ...

43. junit can't find class:***Test    stackoverflow.com

My classpath is defined as follows:

CLASSPATH:%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JUNIT_HOME%\junit.jar
JUNIT_HOME:C:\Program Files\Java\junit3.8.2 
At the cmd line, I input: java junit.swingui.TestRunner junit.samples.AllTests however, it says :
Class not found: junit.samples.AllTests

44. Could not find class: org.junit.tests.AllTests - OSX    stackoverflow.com

I'm having a little trouble getting started with JUnit tests. This should be pretty basic. I downloaded junit-4.8.2.jar from JUnit.org and placed it in my home directory. If I try to ...

45. How do I run JUnit tests during my Ant build script while omitting test classes from my resulting jar?    stackoverflow.com

I'm using the Hello World with Ant tutorial from the Ant manual to learn about Ant. The last part of the tutorial involves adding JUnit tests to the project. I've got everything working ...

46. is it possible to make test method parameterized, not an entire class?    stackoverflow.com

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

47. Where to place a supplementary classes, used in JUnit?    stackoverflow.com

My unit tests need supplementary classes, mostly as factories for creating objects of classes under test. For example:

// EmployeeTest.java
public class EmployeeTest {
  @Test public void testName() {
    ...

48. junit 4 TransactionalTestExecutionListener insert test data only once for all tests in class?    stackoverflow.com

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

49. How to isolate other methods in the same class using EasyMock    stackoverflow.com

I have a method that invokes other method in the same class such as:

Class MyClass{
   public int methodA(){
      ...
      ...

50. running test cases from a java class    stackoverflow.com

I have say 10 test cases, and i want to run them from a java class, i can get the Junit's class name only at runtime. Is it possible to do ...

51. How to cover methods of inner classes?    stackoverflow.com

I'm faced with a problem on how to cover methods of my innner classes. I have a small GUI (swing) application with several buttons and defined action listeners in form of ...

52. Error when defining inner classes in a Test class in JUnit    stackoverflow.com

I'm having some problems when defining inner classes in a Test class inherited from TestCase, for JUnit 3. Scenario is like following: Foo.java

public class Foo {
  public void method() { ... ...

53. Testing a final class in JUnit    stackoverflow.com

All, I have a class file that is used to store all the constants that would be used throughout my application. The class file contains only constants and methods JUnit test case ...

54. How to find out if a method call originated from Test Class    stackoverflow.com

Hii... Is there any way to find out if the method call originated from a test class? If its from a test class... then I need to initialize some dummy values for ...

55. Test an abstract class having constructor with arguments    stackoverflow.com

I have to test one of my abstract classes which is implementing one of the interfaces. The abstract class is having a constructor with arguments. I am using Mockito as the testing framework. So ...

56. Using javaagent with Junit is causing ClassNotFoundException in Class.forName    stackoverflow.com

java -classpath requiredclasspath org.junit.runner.JUnitCore some.package.HelloWorldTest
results in:
JUnit version 4.8.1
.

Time: 0.005

OK (1 test)
But:
java -javaagent:agent.jar -classpath requiredclasspath org.junit.runner.JUnitCore some.package.HelloWorldTest    
results in:
JUnit version 4.8.1
Could not find class: some.package.HelloWorldTest

Time: 0.001

OK (0 tests)
The core ...

57. Java: how to "restart" a static class?    stackoverflow.com

I have a static class (Foo) and a main class (Main) See Main.java:

public class Main {

    public static void main(String[] args) {
        ...

58. How can I run (or change the order of) specific test-methods in a JUnit test class?    stackoverflow.com

I am fairly new to Java. I have constructed a single JUnit test class and inside this file are a number of test methods. When I run this class (in ...

59. How to check if a Java class contains JUnit4 tests?    stackoverflow.com

I have a Java class. How can I check if the class contains methods that are JUnit4 tests? Do I have to do an iteration on all methods using ...

60. How to mock object with constructor that takes a Class?    stackoverflow.com

This is the test:

import static junit.framework.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.whenNew;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest( {ClassUnderTesting.class} )
public class ClassUnderTestingTest {

    @Test
    public void shouldInitializeMocks() throws Exception ...

61. JUnit : Is there a way to skip a test belonging to a Test class's parent?    stackoverflow.com

I have two classes:

public abstract class AbstractFoobar { ... }
and
public class ConcreteFoobar extends AbstractFoobar { ... }  

I have corresponding test classes for these two classes:
public class AbstractFoobarTest { ... ...

62. How to run tearDown type method for a specific test in JUnit class with multiple tests?    stackoverflow.com

I have a junit testCase class with multiple test methods in it ( As requirement , we don't want to create separate class for each test.) I wanna create a tearDown type ...

63. Cobertura test coverage does not cover tests which extend class under test    stackoverflow.com

I have a class which I need to test eg. MyClass.java I am using Junit4 so in order to test the protected methods as well in MyClass.java I create a test class ...

64. Run JUnit test againsts arbitrary loaded class    stackoverflow.com

As part of a larger project, I am attempting to achieve something that I'm not sure is possible, so am eager to see if anyone has any suggestions! The overall system:
As a ...

65. How to Replace The Call to A Private Method of The Class Being Tested    stackoverflow.com

Well, I am right now testing legacy code. And, I am somewhere near to pass this test, but its stuck at the line having comments on it. Here is the snippet

 ...

66. PowerMock testing - set static field of class    stackoverflow.com

I'm having difficulty finding a way to set a static field of a class. It's basically like this: public class Foo { // .... static B ...

67. How to add a class path in vimscript    stackoverflow.com

I'm working on a simple vim script that will allow me to hit F6 and run a single jUnit test for some java class. So far I can get JUnit to work ...

68. JUnit tool classes package    stackoverflow.com

As I'm currently adding more unit test to our code, I'm stuck because of a simple problem. I need to write some boilerplate code to make it easy to write test classes. ...

69. multiple test classes for an interface rolled up into a suite in junit 4?    stackoverflow.com

I have an interface that defines the behaviour of an object that does some graph search called say GraphSearcher. I currently have a bunch of different implementations with more variations on ...

70. How can I run a custom JUnit4 Runner on JUnit3 test classes with Ant?    stackoverflow.com

We have test classes which are built on Spring 2.0.8's AbstractTransactionalDataSourceSpringContextTests. There are a huge number of these, all of which are written in JUnit3 style. In order to use JUnit 4 ...

71. Problem compiling Junit classes    stackoverflow.com

I have my java project compiled and working fine but now I want to compile the JUnit tests and I'm having some trouble doing it. I have all the tests.java in /test/model, ...

72. how to mock class which calls singleton class using junit    stackoverflow.com

I would like to test a method from class1 which calls the singleton class getInstance:

Class ivDomain {

    public String method1() {

        ...

73. Test class with a new() call in it with Mockito    stackoverflow.com

A have a legacy class that contains a new() call to instantiate a LoginContext():

public class TestedClass {
  public LoginContext login(String user, String password) {
    LoginContext lc = ...

74. testing methods that accept Class arguments    stackoverflow.com

I'm trying to figure out how test a small library I'm working on . Using this simplified method as an example:

private int countMappableFields(Class<?> type) {
    int mappableFields = ...

75. Java JUnit, Interfaces, Class Headings    stackoverflow.com

A programmer has to write a program for an xyz program. He has recognised that both the Div and Add values are based on the same underlying Op data structure. As ...

76. when using JUNIT 4.8 categories , the report generated does not show the actual class how to overcome this?    stackoverflow.com

i m new to junit and i used testNg before i use junit 4.8 categoreis feature to group my test cases and when i generate the report using test cases it ...

77. Guice: Why must @Singleton-annotated classes be immutable/thread safe?    stackoverflow.com

NOTE: This question is not about Singleton classes as described in Gamma94 (ensuring only one object ever gets instantiated.) I read the Guice documentation about the @Singleton attribute:

Classes annotated ...

78. Junit Reports only showing the last class ran when executed with build.xml    stackoverflow.com

I can get the build.xml to report all of my classes defined by targets if I call test-all, but if i only want to run a few targets my Junit report ...

79. JUnit4 @Test(expected=MyException.class) VS try/catch    stackoverflow.com

I'm pondering on exception handling and unit tests best practices because we're trying to get some code best practices in place. A previous article regarding best practices, found on our company wiki, ...

80. Class object not the same type as a Test object? Junit    stackoverflow.com

I'm trying to write some code which recursively adds TestSuites in a project to a suite of suites located at the root of the package hierarcy. I've already written the code ...

81. use its own class in a static method in Java    stackoverflow.com

I have several junit test cases that extend an AbstractTest. They're all required to have a static method suite(). However people usually copy&paste old test case to make new one, and ...

82. JUnit test classes are not coming while creating JUnit test suit    stackoverflow.com

I tried to create JUnit Test Suite in eclipse by following the steps- Right click on the source folder -> New -> Other -> JUnit Test Suit. The issue is I ...

83. how to mock method from calling class using mockito in java    stackoverflow.com

I have a class that calls method from another class to get the report status.

Class A {
  private classb b = new classb();
  method x() {
    ...

84. Many Test classes or one Test class with many methods?    stackoverflow.com

I have a PersonDao that I'm writing unit tests against. There are about 18-20 methods in PersonDao of the form -

    getAllPersons() 
    getAllPersonsByCategory()
  ...

85. annotation to make a private method public only for test classes    stackoverflow.com

Who has a solution for that common need. I have a class in my application. some methods are public, as they are part of the api, and some are private, as they for internal ...

86. Junit test class variable scope    stackoverflow.com

I have a Junit test class with two tests in it. test 1 will add an element to an ArrayList and passes it to the main class to do some logic ...

87. Is it advisable to write a test case for every class in your program?    stackoverflow.com

Im am just getting introduced to unit testing and test driven development. Thus far, I have only used Junit as testing framework. A question which emerged and for which I have ...

88. Is mockito supposed to call default constructor of mocked class?    stackoverflow.com

I'm trying to create a Mockito mock object of a class with some rather heavy network and transaction behavior which I don't want to have to deal with in the current ...

89. Dynamically adding JUnit tests to a test class    stackoverflow.com

I find myself writing lots and lots of boiler plate tests these days and I want to optimize away a lot of these basic tests in a clean way that can ...

90. force private member access from same class only through method in java    stackoverflow.com

I want to force future users of a class to access a private member also from future code written in that class only through an accessor method (even through junit or ...

91. Not able to write the testcases for inner class using EasyMock    stackoverflow.com

I am new to the EasyMock. I need to test my class using the EasyMock. but here the problem is my class has inner class and this inner class is instatiated ...

92. How to test abstract class in Java with jUnit?    stackoverflow.com

I am very new to Java testing with jUnit. Till today, I was using Python and its unit test class unittest. Now, I have to work with Java and ...

93. How can I run a set of junit tests in multiple test classes?    stackoverflow.com

In my webapp, there are multiple screens that have common webElements. I want to assert that all these common elements exist on each page. But I don't want to put all ...

94. Could not find class Java JUnit    stackoverflow.com

I'm begginer in Java. Can you help me to find error? I run this using command line in Windows from the root folder of project.

java -classpath lib/junit.jar;classes/ua/edu/sumdu/j2se/savchenko/pr2/Task.class
org.junit.runner.JUnitCore ua.edu.sumdu.j2se.savchenko.pr2.tests.TaskTest
My files location:
classes/ua/edu/sumdu/j2se/savchenko/pr2/Task.class
classes/ua/edu/sumdu/j2se/savchenko/pr2/tests/TaskTest.class
lib/junit.jar

95. TestNG dependsOnMethods from different class    stackoverflow.com

dependsOnMethods attribute of the @Test annotation works fine when the test to be depended upon is in the same class as that of the test that has this annotation. But it ...

96. Running Junit through Ant does not seem to use custom class runner    stackoverflow.com

I have a custom runner that ships Junit tests over a socket connection to a Junit server running on other hardware. The tests run as intended with the following target:

  ...

97. JUnit Could not find class: package_name.class    stackoverflow.com

I just dropped the JUnit folder into /System/Library/Java/Extensions/. I'm able to get JUnit to run, but it can't find my test class. I'm running this command (plus a few variants) from the ...

98. ClassLoader throws NullPointerException when trying to partial mock a class with JMockit    stackoverflow.com

Using Eclipse 3.6.1
Java 1.6.0_26
JMockit 0.999.10 UPDATE: I was able to create a SSCCE, which I am posting below: UPDATE2: Added DaemonHelper. Additionally, if I remove DaemonHelper from the constructor, I get a ClassCircularityError ...

99. Testing Java class    stackoverflow.com

I am testing Java app with JUnit. The following is the source code of a specific method:

  public class Surgery {

        Vector<Patient> patients;
 ...

100. Testing Java class using JUnit    stackoverflow.com

public void printSummaryForPatient(String name){
    Patient p = findPatient(name);
    p.printPatientSummary();
    p.computeBMI();
}
My method to test:
@Test
public void testPrintSummaryForPatient() {

    Patient patient_adult=new Patient("Ted",24,1.90,70.0,"Leicester");
 ...

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.