Search Results

Search found 22 results on 1 pages for 'jmock'.

Page 1/1 | 1 

  • How to get started with testing(jMock)

    - by London
    Hello, 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 : http://www.theserverside.com/news/1365050/Using-JMock-in-Test-Driven-Development http://jeantessier.com/SoftwareEngineering/Mocking.html#jMock And most articles I found was about test driven development, write tests first then write code to make the test pass. I'm not looking for that at the moment, I'm trying to write tests for already existing code with jMock. The official documentation is vague to say the least and just too hard for me. Does anybody have better way to learn this. Good books/links/tutorials would help me a lot. thank you EDIT - more concrete question : http://jeantessier.com/SoftwareEngineering/Mocking.html#jMock - from this article Tried this to mock this simple class : import java.util.Map; public class Cache { private Map<Integer, String> underlyingStorage; public Cache(Map<Integer, String> underlyingStorage) { this.underlyingStorage = underlyingStorage; } public String get(int key) { return underlyingStorage.get(key); } public void add(int key, String value) { underlyingStorage.put(key, value); } public void remove(int key) { underlyingStorage.remove(key); } public int size() { return underlyingStorage.size(); } public void clear() { underlyingStorage.clear(); } } Here is how I tried to create a test/mock : public class CacheTest extends TestCase { private Mockery context; private Map mockMap; private Cache cache; @Override @Before public void setUp() { context = new Mockery() { { setImposteriser(ClassImposteriser.INSTANCE); } }; mockMap = context.mock(Map.class); cache = new Cache(mockMap); } public void testCache() { context.checking(new Expectations() {{ atLeast(1).of(mockMap).size(); will(returnValue(int.class)); }}); } } It passes the test and basically does nothing, what I wanted is to create a map and check its size, and you know work some variations try to get a grip on this. Understand better trough examples, what else could I test here or any other exercises would help me a lot. tnx

    Read the article

  • Jmock mock DAO object

    - by Gandalf StormCrow
    Hi all, I wrote a method that retrieves certain list of strings, given a correct string key. Now when I create a list(the one to be retrieved by method descibed in previous sentence) and create test I can easily get results and test passes successfully. Now on the other hand if I save the content of this list to database in 2 columns, key and value I wrote a class which retrieves this items with method inside it. And when I print it out to console the expected results are correct, now I initialize my DAO from application context where inside its bean it gets session and because of DAO works. Now I'm trying to write a test which will mock the DAO, because I'm running test localy not on the server .. so I told jmock to mock it : private MyDAO myDAO; in the setup() myDAO = context.mock(MyDAO.class); I think I'm mocking it correctly or not, how can I mock this data from database? what is the best way? Is there somewhere good Jmock documentation? on their official site its not very good and clear, you have to know what you seek in order to find it, can't discover something cool in the mean time.

    Read the article

  • Cactus versus mock objects (jMock, Easy mock)

    - by Thomman
    I'm little confused with Cactus and mock objects (jMock, Easy mock). Could anyone please answer the following questions? When to use Cactus for testing? When not to use Cactus for testing? When to use mock objects for testing? When not to use mock objects for testing?

    Read the article

  • using JMock to write unit test for a simple spring JDBC DAO

    - by Quincy
    I'm writing an unit test for spring jdbc dao. The method to test is: public long getALong() { return simpleJdbcTemplate.queryForObject("sql query here", new RowMapper<Long>() { public Long mapRow(ResultSet resultSet, int i) throws SQLException { return resultSet.getLong("a_long"); } }); } Here is what I have in the test: public void testGetALong() throws Exception { final Long result = 1000L; context.checking(new Expectations() {{ oneOf(simpleJdbcTemplate).queryForObject("sql_query", new RowMapper<Long>() { public Long mapRow(ResultSet resultSet, int i) throws SQLException { return resultSet.getLong("a_long"); } }); will(returnValue(result)); }}); Long seq = dao.getALong(); context.assertIsSatisfied(); assertEquals(seq, result); } Naturally, the test doesn't work (otherwise, I wouldn't be asking this question here). The problem is the rowmapper in the test is different from the rowmapper in the DAO. So the expectation is not met. I tried to put with around the sql query and with(any(RowMapper.class)) for the rowmapper. It wouldn't work either, complains about "not all parameters were given explicit matchers: either all parameters must be specified by matchers or all must be specified by values, you cannot mix matchers and values"

    Read the article

  • Using jmock how to reuse parameter

    - by BenZen
    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 question, i use an id. My id is generated using an UUID. an i want to retrieve this id, wich is given as a parameter to a mocked object. It look like this: oneOf(message).setJMSCorrelationID(with(correlationId)); inSequence(sequence); Where correlationId is the string i'd like to keep for an other expecteation like this one: oneOf(session).createBrowser(with(inputChannel), with("JMSType ='pong' AND JMSCorrelationId = '"+correlationId+"'")); have you got an answer?

    Read the article

  • What is the best way to use Guice and JMock together?

    - by Yishai
    I have started using Guice to do some dependency injection on a project, primarily because I need to inject mocks (using JMock currently) a layer away from the unit test, which makes manual injection very awkward. My question is what is the best approach for introducing a mock? What I currently have is to make a new module in the unit test that satisfies the dependencies and bind them with a provider that looks like this: public class JMockProvider<T> implements Provider<T> { private T mock; public JMockProvider(T mock) { this.mock = mock; } public T get() { return mock; } } Passing the mock in the constructor, so a JMock setup might look like this: final CommunicationQueue queue = context.mock(CommunicationQueue.class); final TransactionRollBack trans = context.mock(TransactionRollBack.class); Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(CommunicationQueue.class).toProvider(new JMockProvider<QuickBooksCommunicationQueue>(queue)); bind(TransactionRollBack.class).toProvider(new JMockProvider<TransactionRollBack>(trans)); } }); context.checking(new Expectations() {{ oneOf(queue).retrieve(with(any(int.class))); will(returnValue(null)); never(trans); }}); injector.getInstance(RunResponse.class).processResponseImpl(-1); Is there a better way? I know that AtUnit attempts to address this problem, although I'm missing how it auto-magically injects a mock that was created locally like the above, but I'm looking for either a compelling reason why AtUnit is the right answer here (other than its ability to change DI and mocking frameworks around without changing tests) or if there is a better solution to doing it by hand.

    Read the article

  • Get/save parameters to an expected JMock method call?

    - by Tayeb
    Hi, I want to test an "Adapter" object that when it receives an xml message, it digest it to a Message object, puts message ID + CorrelationID both with timestamps and forwards it to a Client object.=20 A message can be correlated to a previous one (e.g. m2.correlationID =3D m1.ID). I mock the Client, and check that Adapter successfully calls "client.forwardMessage(m)" twice with first message with null correlationID, and a second with a not-null correlationID. However, I would like to precisely test that the correlationIDs are set correctly, by grabing the IDs (e.g. m1.ID). But I couldn't find anyway to do so. There is a jira about adding the feature, but no one commented and it is unassigned. Is this really unimplemented? I read about the alternative of redesigning the Adapter to use an IdGenerator object, which I can stub, but I think there will be too many objects.=20 Don't you think it adds unnecessary complexity to split objects to a so fine granularity? Thanks, and I appreciate any comments :-) Tayeb

    Read the article

  • NetBeans Platform Unit Test Library Dependencies

    - by Ben Hammond
    I am working on a Netbeans Platform RCP application. I use jmock in my unit tests and I have created a Library Wrapper Module to import the necessary libraries. The Module has an section named 'Libraries' and another section named 'Unit Test Libraries'. I hoped that I could add the JMock Library Wrapper to the 'Unit Test Libraries', however when I run the unit tests I get the error 'package org.jmock does not exist'. If I import the JMock Library Wrapper in to the main 'Libraries' element then it works, but this feels wrong. Maven allows me to specify unit-test only dependencies, and I assumed that NetBeans Platform did the same. Should this be possible? Am I doing something wrong? Should I resign myself to a run-time dependency on the unit-test libraries (ugh).

    Read the article

  • Need help with writing test

    - by London
    I'm trying to write a test for this class its called Receiver : public void get(People person) { if(null != person) { LOG.info("Person with ID " + person.getId() + " received"); processor.process(person); }else{ LOG.info("Person not received abort!"); } } Here is the test : @Test public void testReceivePerson(){ context.checking(new Expectations() {{ receiver.get(person); atLeast(1).of(person).getId(); will(returnValue(String.class)); }}); } Note: receiver is the instance of Receiver class(real not mock), processor is the instance of Processor class(real not mock) which processes the person(mock object of People class). GetId is a String not int method that is not mistake. Test fails : unexpected invocation of person.getId() I'm using jMock any help would be appreciated. As I understood when I call this get method to execute it properly I need to mock person.getId() , and I've been sniping around in circles for a while now any help would be appreciated.

    Read the article

  • Unit test helper methods?

    - by Aly
    Hi, I have classes which prviously had massive methods so i subdivided the work of this method into 'helper' methods. These helper methods are declared private to enforce encapsulation - however I want to unit test the big public methods, is it good to unit test the helper methods too as if one of them fail the public method that calls it will also fail - but this way we can identify why it failed. Also in order to test these using a mock object I would need to change their visibility from private to protected, is this desirable?

    Read the article

  • Can anyone help why my mockery doesn't work?

    - by user509550
    The test call real method(service) without mocking some expecations @Test public void testPropertyList() { Credentials creds = new Credentials(); creds.setUsername("someEmail"); creds.setPassword("somePassword"); creds.setReferrer("someReferrer"); final Collection<PropertyInfo> propertyInfoCollection = new LinkedList<PropertyInfo>(); final List<ListingInfo> listings = new ArrayList<ListingInfo>(); listings.add(listingInfoMock); listings.add(listingInfoMock); propertyInfoCollection.add(new PropertyInfo("c521bf5796274bd587c00bec80583c00", listings)); MultivaluedMap<String, String> params = new MultivaluedMapImpl(); params.add("page", "5"); params.add("size", "5"); instance.setPropertyListFacade(propertyListFacadeMock); mockery.checking(new Expectations() { { one(propertyListFacadeMock).getUserProperties(); will(returnValue(propertyInfoCollection)); one(listingInfoMock).getPropertyName(); allowing(listingInfoMock).getThumbnailURL(); one(listingInfoMock).getListingSystemId(); one(listingInfoMock).getPropertyURL(); one(listingInfoMock).getListingSystemId(); one(listingInfoMock).getPropertyURL(); } }); instance.setSessionManager(dashboardSessionManagerMock); testSuccessfulAuthenticate(); ClientResponse response = resource.path(PROPERTIES_PATH).queryParams(params).accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(200, response.getStatus()); mockery.assertIsSatisfied(); }

    Read the article

  • Why do we need mocking frameworks like Easymock , JMock or Mockito?

    - by Praneeth
    Hi, We use hand written stubs in our unit tests and I'm exploring the need for a Mock framework like EasyMock or Mockito in our project. I do not find a compelling reason for switching to Mocking frameworks from hand written stubs. Can anyone please answer why one would opt for mocking frameworks when they are already doing unit tests using hand written mocks/stubs. Thanks

    Read the article

  • iPhone Provisioning Profile problems...

    - by James
    I have already successfully submitted two apps to the app store, so I should be able to do it by now, right? With my most recent app, however, I'm having a bear of a time with getting the Application Identifier or Bundle Identifier set up. In my distribution profile, I have included the identifier "com.jmock.irowbeta", and then copied it exactly into the the app's Info.plist file under "Bundle Identifier". In the past, this has done the trick, but now I'm getting the error Provisioning profile 'irow beta' specificies the identifier 'com.jmock.irowbeta' which doesn't match the current setting 'com.yourcompany.irow-beta'. So it seems that its somehow still using the default of com.yourcompany.APPLICATION_NAME, but it shouldn't after I have changed it in the Info.plist, right? I think this means that xcode isn't recognizing that PLIST for some reason, because when I change the name of the icon file, for example, or other such attributes, nothing changes. If this is the problem, how do I make xcode recognize the PLIST? Otherwise, what the heck is going on? Thanks, James

    Read the article

  • question about learning TDD

    - by Gandalf StormCrow
    what are the best books to learn about junit, jmock and testing generally? Currently I'm reading pragmatic unit testing in Java, I'm on chapter 6 its good but it gets complicated.. is there a book for a bottom up? from your expirience which helped you get the testing concept

    Read the article

  • Trying to write junit test missing some basisc

    - by Gandalf StormCrow
    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 found it here I never used these options before but I need to write this test, I can do it jmock as well but I don't know how .. I need to compare my expected results let say 0, if the real result is greater that the test should fail.

    Read the article

  • Best current framework for unit testing EJB3 / JPA

    - by kennygrimm
    Starting new project using EJB 3 / JPA, mainly stateless session beans and batch jobs. I've used JUnit in the past on standard Java webapps and it seemed to work pretty well. In EJB2 unit testing was a pain and required a running container such as JBoss to make the calls into. Now that we're going to be working in EJB3 / JPA I'd like to know what companies are using to write and run these tests. Are Junit and JMock still considered relevant or are there other newer frameworks that have come around that we should investigate?

    Read the article

  • C# testing framework that works like JUnit in Eclipse?

    - by bluebomber357
    Hello all, I come from a Java/Eclipse background and I fear that I am spoiled by how easy it is to get JUnit and JMock running in Eclipse, and have that GUI with the bar and pass/fail information pop up. It just works with no hassle. I see a lot of great options for testing in C# with Visual Studio. NUnit looks really nice because it contains unit and mock testing all in one. The trouble is, I can't figure out how to get the IDE display my results. The NUnit documentation seems to show that it doesn't automatically show results through the VS IDE. I found http://testdriven.net/, which seems to trumpet that is makes VS display these stats and work with multiple frameworks, but it isn't open source. Is there anyway to get unit and mock testing working with the VS IDE like it does in Java with Eclipse?

    Read the article

  • Is there any disadvantage to putting API code into a JAR along with the classes?

    - by Adam Gent
    In Java if you package the source code (.java) files into the jar along with classes (.class) most IDE's like eclipse will show the javadoc comments for code completion. IIRC there are few open-source projects that do this like JMock. Lets say I have cleanly separated my API code from implementation code so that I have something like myproject-api.jar and myproject-impl.jar is there any reason why I should not put the source code in my myproject-api.jar ? Because of Performance? Size? Why don't other projects do this?

    Read the article

  • Is it bad practice to make a setter return "this"?

    - by Ken Liu
    Is it a good or bad idea to make setters in java return "this"? public Employee setName(String name){ this.name = name; return this; } This pattern can be useful because then you can chain setters like this: list.add(new Employee().setName("Jack Sparrow").setId(1).setFoo("bacon!")); instead of this: Employee e = new Employee(); e.setName("Jack Sparrow"); ...and so on... list.add(e); ...but it sort of goes against standard convention. I suppose it might be worthwhile just because it can make that setter do something else useful. I've seen this pattern used some places (e.g. JMock, JPA), but it seems uncommon, and only generally used for very well defined APIs where this pattern is used everywhere. Update: What I've described is obviously valid, but what I am really looking for is some thoughts on whether this is generally acceptable, and if there are any pitfalls or related best practices. I know about the Builder pattern but it is a little more involved then what I am describing - as Josh Bloch describes it there is an associated static Builder class for object creation.

    Read the article

1