What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?
|
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 ... |
Say I have class A with
class A {
final String foo() {
// .. computing result, contacting database, whatever ..
return "some computed value";
...
|
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 ... |
I have a factory that returns an interface FormatService:
public class FormatServiceFactory {
public FormatService getService() {
...
...
|
I have a method that looks similar to the following:
public void myMethod(MyClass c)
{
if (c == null)
{
return;
}
try
{
...
|
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
|
|
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 ... |
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 ... |
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?
... |
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 ... |
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 ... |
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 ...
|
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 ... |
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 ... |
I like to know what mock objects are in Java. Why do we create them and what are their uses?
|
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 ... |
See the following Mock Test by using Spring/Spring-MVC
public class OrderTest {
// SimpleFormController
private OrderController controller;
private OrderService service;
...
|
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 :
|
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 ... |
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 ... |
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);
...
|
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 ... |
This is the class that I have to test:
public class Downloader {
public String download(String uri) {
HttpClient client = this.getHttpClient();
client.setURI(uri);
...
|
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 ... |
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 ...
|
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");
...
|
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 ... |
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()
...
|
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 ... |
I have an enum switch more or less like this:
public static enum MyEnum {A, B}
public int foo(MyEnum value) {
switch(value) {
...
|
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 ...
|
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 ... |
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 ... |
I got the following method:
private MessageDigest getMessageDigest() {
try {
return MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
...
|
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 ... |
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 ... |
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;
...
|
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;
...
|
Let's say I wrote a pretty simple class called ValueFinder that looks like this:
public class ValueFinder {
public String findValue(Object obj) {
...
|
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 ... |
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 ... |
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 ... |
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 ...
|
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 ... |
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: ... |
|
|
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 ... |
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 ... |