Mock « Tools « 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 » Tools » Mock 

1. What's the best mock framework for Java?    stackoverflow.com

What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?

2. Mocking Static Blocks in Java    stackoverflow.com

My motto for Java is "just because Java has static blocks, it doesn't mean that you should be using them." Jokes aside, there are a lot of tricks in Java that ...

3. How to go about mocking a class with final methods?    stackoverflow.com

Say I have class A with

class A {
  final String foo() {
    // .. computing result, contacting database, whatever ..
    return "some computed value";
 ...

4. How to mock classes instantiated as local variables    stackoverflow.com

I'm writing tests for a business method that invokes some DAO classes to perform operations over a database. This method, firstly retrieves a JDBC connection from a DataSource object, The same connection ...

5. Can I use jmock to replace an implementation returned by a factory?    stackoverflow.com

I have a factory that returns an interface FormatService:

public class FormatServiceFactory {
    public FormatService getService() {
        ...
   ...

6. Creating a mock with Jmock to return a null value for itself    stackoverflow.com

I have a method that looks similar to the following:

public void myMethod(MyClass c)
{
  if (c == null)
  {
    return;
  }
  try
  {
  ...

7. Mock svn instance for testing svnkit tests    stackoverflow.com

A project I'm working on interacts heavily with Subversion, using svnkit. Are there any examples on running a mock in-memory svn instance, to help facilitate testing etc? Cheers Marty

8. Test and Mock framework for Java and .NET    stackoverflow.com

I'd like to know your thoughts about test/mocking frameworks that are widely used and have a good level of compatibility between Java and .NET. I mean, I want to learn those ...

9. In Need of Refactoring in Order to Improve Testability    stackoverflow.com

I'm testing a simple DAO layer with mockito but I found a problem, basically a hard to test interface and I was wondering if you could give me some insight... This is ...

10. Mocking vs. faking, when to use what?    stackoverflow.com

Can anyone come up with a guidelines kind of stuff, suggesting the ideal scenarios when to go for mocking or faking (setting up the essentials manually). Bit confused with the approach? ...

11. Mocking / Testing a core object in my system    stackoverflow.com

I've been asked to work on changing a number of classes that are core to the system we work on. The classes in question each require 5 - 10 different related ...

12. Mocking inter-method dependencies    stackoverflow.com

I've recently started using mock objects in my tests, but I'm still very inexperienced with them and unsure of how to use them in some cases. At the moment I'm struggling ...

13. how to mock a parametrized constructor?    stackoverflow.com

I've the following class. It has the code to connect to SAP in its constructor. There is an abstract method(the subclasses define the implementation) which I want to mock.

public abstract class ...

14. Use of Mocks in Tests    stackoverflow.com

I just started using mock objects (using Java's mockito) in my tests recently. Needless to say, they simplified the set-up part of the tests, and along with Dependency Injection, I ...

15. Save object in debug and than use it as stub in tests    stackoverflow.com

My application connects to db and gets tree of categories from here. In debug regime I can see this big tree object and I just thought of ability to save this ...

16. What are mock objects in Java?    stackoverflow.com

I like to know what mock objects are in Java. Why do we create them and what are their uses?

17. mocking a singleton class    stackoverflow.com

I recently read that making a class singleton makes it impossible to mock the objects of the class, which makes it difficult to test its clients. I could not immediately understand ...

18. Mock versus Implementation. How to share both approaches in a single Test class?    stackoverflow.com

See the following Mock Test by using Spring/Spring-MVC

public class OrderTest {

    // SimpleFormController
    private OrderController controller;
    private OrderService service;

   ...

19. How to get started with testing(jMock)    stackoverflow.com

I'm trying to learn how to write tests. I'm also learning Java, I was told I should learn/use/practice jMock, I've found some articles online that help to certain extend like :

20. Using jmock how to reuse parameter    stackoverflow.com

I'm building a test, in wich i need to send question, and wait for the answer. Message passing is not the problem. In fact to figure out wich answer correspond to wich ...

21. Java Instantiate Abstract Class or Partially Implemented Interface    stackoverflow.com

I have an interface that has about 20 methods (huge). I want to create a single instance for testing purposes, but I only need to override one method. What's a good way ...

22. Having trouble understanding how to use Mock in a Unit-Test    stackoverflow.com

I have defined the following Unit-Test:

[TestMethod] //@Test for the Java crowd
public void In_The_Beginning_All_The_Board_Is_Black()
{
    IBoard board = new Board(new Size(10, 22));
    BoardEngine boardEngine = new BoardEngine(board);

 ...

23. Using soapUI API to create a soapUI Mock object    stackoverflow.com

I try to create a soap UI WSDL Mock Service using the soapUI API. But there seems to be no documentation of the source code. Has anyone done this before or ...

24. How to design a private/final method available for mocking?    stackoverflow.com

This is the class that I have to test:

public class Downloader {
  public String download(String uri) {
    HttpClient client = this.getHttpClient();
    client.setURI(uri);
   ...

25. How to Mock Static Java methods with JRuby and Mocha?    stackoverflow.com

My goal is to unit test legacy Java code, riddled with static utility methods, using JRuby and Mocha. Is this possible? I am trying to apply similar techniques that are available ...

26. Unit-testing method invocation (template method)?    stackoverflow.com

Is it possible to unit-test method invocation on the same class(in order and how many times they were invoked) ? i.e. A Template Method like the one below:

    abstract ...

27. How can I mock JodaTime actual date?    stackoverflow.com

I want to test this method:

 public FirmOrder findActiveByModelColor(ModelColor modelColor) {
   Query query = em.createQuery("FROM FirmOrder fo WHERE fo.modelColor = :modelColor AND fo.year = :year AND fo.month = :month");
 ...

28. mailserver mock for integration tests inside cargo    stackoverflow.com

I've got a web application i'm currently testing on different levels (junit tests, integration tests within cargo container running a tomcat, htmlunit etc.) and i'm facing a problem now. With some ...

29. Testing a Builder Pattern    stackoverflow.com

I'm trying to unit test a builder style pattern which looks like this (mockedObject is injected into the function so I can mock it):

Thing thing = 
    mockedObject.createThing()
 ...

30. Is it wise to use mocking in BDD test cases?    stackoverflow.com

We are going to implement a small java application with BDD, which reads an MS excel sheet using POI of apache.org and prints some text based on that excel to the ...

31. Mocking Java enum to add a value to test fail case    stackoverflow.com

I have an enum switch more or less like this:

public static enum MyEnum {A, B}

public int foo(MyEnum value) {
    switch(value) {
        ...

32. PowerMock: java.lang.IllegalAccessError: java.lang.Class when mocking java.util.ServiceLoader    stackoverflow.com

I am trying to mock the java ServicesLoader (which is final) in my tests with PowerMock, and it seems to fail... The simplest test case that reproduces the error is this:

import java.util.ServiceLoader;
import ...

33. What is the difference between mocks and stubs ( JMock)    stackoverflow.com

What is the difference between mocks and stubs in jMock? I can create both with jMock? how i can create stubs with it and what the situation is most appropriate for ...

34. A mock management system?    stackoverflow.com

I'm just curious if there is any software, that could help me with mock management and creation - I prefer Java and .net but I'll be happy to see it for ...

35. Mocking MessageDigest.getInstance() to throw an exception    stackoverflow.com

I got the following method:

private MessageDigest getMessageDigest() {
    try {
        return MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
  ...

36. Java Mock Framework that supports Actual Results, and Static Methods    stackoverflow.com

This question may have been asked before but I have very specific things that I am looking for. I would like to integrate unit testing into a legacy web application ...

37. Why should I use mock objects (Java)? Do all mocking frameworks serve the same purpose?    stackoverflow.com

Possible Duplicate:
What is the purpose of mock objects?
I'm preparing a presentation and I need to get a better understanding of what mocking is, what ...

38. configurable dependencies with easy to mock out default implementations    stackoverflow.com

I'm working on a kind of parameter values parser library. I'd like to have an Parser defined as follows:

public class Parser {

    private ValuesConfiguration configuration;
    ...

39. When to avoid mocking?    stackoverflow.com

The most common use case for mocking is

objA uses objB;
use objA without having objB populated/initialized
so that
@Mock
private UserInterface userInterface;

public void method() {
   MockitoAnnotations.initMocks(this);
   Client client;
  ...

40. How do you not do partial mocking in this scenario?    stackoverflow.com

Let's say I wrote a pretty simple class called ValueFinder that looks like this:

public class ValueFinder {

    public String findValue(Object obj) {
       ...

41. Mockable helper class for java.util.Date    stackoverflow.com

I'd like to have a helper class for getting the current date. I want to avoid having new Date() in code because of future testing issues (may need to return different ...

42. How to write a UT to mock an internal object in one method?    stackoverflow.com

For example , I have a java class as below. I am going to write a unit test for doWork(), so I would like to control obj's behavior. But it is ...

43. Java detect if class is a proxy    stackoverflow.com

Is it possible to detect if a class is a proxy (dynamic, cglib or otherwise)? Let classes Aand B implement a common interface I. Then I need to define a routine ...

44. Power Mock - assertion error when mocking final class    stackoverflow.com

I was trying to mock certian scenarios using Power Mock. I am getting assertion error on below test fn - returnSevenTest() . Class to be Tested package tutorial.one; public class TutorialOne { //field

private ...

45. Got ExceptionInInitializerError when mocking constructor of a class with Powermock. How to fix it?    stackoverflow.com

Here is my case. I have a AbstractController class. It has a sub class Controller. In one of AbstractController's methods a new ApplicationLock is instantiated. I'd like to mock ApplicationLock when ...

46. How to mock a method which relies on updating mutable objects    stackoverflow.com

I have a method which doesn't return a value. It instead accepts a list and modifies the members of this list. Obviously the list itself is mutable, as are its members. EG: ...

47. question about mock test    coderanch.com

49. Mocking a class for Testing    java-forums.org

If I have a class called Library with a method as shown below public String searchForBook(){ String bookNumberToBeSearched = new InputAndOutputHandling().obtainStringFromKeyboard( "Book Number"); ......... ......... } where class InputAndOutputHandling { public String obtainStringFromKeyboard(String anotherString) { ................. ................. } } If i am writing a test for Library class and the method shown above, how will i mock the IO handling class ...

50. Question about mock testing and large amounts of expectations    forums.oracle.com

I have been using mock testing for a while now and it seems really useful. I have one nagging problem with it though. Whenever I write tests that require mock objects that have a lot of calls made on them, my expectations become huge and tedious to write. It seems like there is no way around this either. The expectations must ...

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.