You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(30) |
Sep
(19) |
Oct
(3) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(11) |
Feb
(13) |
Mar
(10) |
Apr
(11) |
May
(7) |
Jun
(8) |
Jul
(5) |
Aug
(16) |
Sep
(14) |
Oct
(3) |
Nov
(9) |
Dec
|
2003 |
Jan
(5) |
Feb
(6) |
Mar
(9) |
Apr
(31) |
May
(25) |
Jun
(22) |
Jul
(28) |
Aug
(27) |
Sep
(19) |
Oct
(4) |
Nov
(7) |
Dec
(26) |
2004 |
Jan
(8) |
Feb
(13) |
Mar
(5) |
Apr
(8) |
May
(8) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(4) |
2005 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2008 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(3) |
May
|
Jun
|
Jul
(6) |
Aug
|
Sep
(10) |
Oct
(6) |
Nov
|
Dec
(36) |
2009 |
Jan
(3) |
Feb
(14) |
Mar
(13) |
Apr
(18) |
May
(35) |
Jun
(18) |
Jul
(27) |
Aug
(6) |
Sep
(2) |
Oct
|
Nov
|
Dec
(10) |
2010 |
Jan
(6) |
Feb
(1) |
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
From: Steve F. <st...@m3...> - 2003-04-30 14:51:46
|
I never had the time to do it. The public API selects a provider implementation based on some kind of lookup and calls through to it. In theory, we could intercept that lookup and make it call through to a mock implementation that we provide. S. James Howe wrote: > Ok, I found those definitions but I guess I'm a little fuzzy on how to > best make use of them in writing my code and tests. Are there any > examples of how to make use of these classes? I'm assuming this > approach also falls into a pattern for mocking up code which needs to > use functionality normally provided by static methods. I'd be > interested in seeing some examples of this pattern in action as well. |
From: James H. <jw...@al...> - 2003-04-30 14:24:53
|
Ok, I found those definitions but I guess I'm a little fuzzy on how to best make use of them in writing my code and tests. Are there any examples of how to make use of these classes? I'm assuming this approach also falls into a pattern for mocking up code which needs to use functionality normally provided by static methods. I'd be interested in seeing some examples of this pattern in action as well. Thanks. On 30 Apr 2003 12:54:31 +0100, Jeff Martin <je...@mk...> wrote: > The mocks for Transport/Message etc are mocks of the alt.javax > interfaces. Which have both mock and real implementations. The real > implementations being wrappers around the javax.mail.* classes. > > http://www.mockobjects.com/javadoc/1.3/alt/javax/mail/package- > summary.html > > On Tue, 2003-04-29 at 19:40, James Howe wrote: >> I'm writing a small utility class which will be used to send e-mail. I >> would like to write the code test-first as much as possible. However, I >> notice that that Java Mail API makes heavy use of static methods to >> accomplish many of its tasks. I see that there are Mock implementations >> of things like Transport and Message in the Mock Objects library, but >> I'm not sure how to make use of them. Are there any simple examples of >> using the MockObjects library to test things that use things like >> javax.mail.Transport (and related classes?) >> >> Thanks. -- James Howe |
From: <DeS...@em...> - 2003-04-30 14:20:21
|
Guys, Here is an interesting article on something the authors call "Virtual Mock Objects". It could become the solution for the non-mockable types that now reside in the "alt" packages. http://www.xprogramming.com/xpmag/virtualMockObjects.htm I thought it might be of interest for the people on this list. Ringo |
From: Steve F. <st...@m3...> - 2003-04-30 13:22:57
|
From what I remember, you can register an implementation to provide mail for a given transport, it's in the API somewhere. When I was looking, I didn't have time to figure out how to plug in to that. S. Griffin Caprio wrote: > Steve, > > Can you expand on what a "mock mail provider" entails? > > -Griffin > --- Steve Freeman <st...@m3...> wrote: > >>One option I considered, but never got around to, >>was to implement and >>register a mock mail provider. >> >>S. >> >>James Howe wrote: >> >>>I'm writing a small utility class which will be >> >>used to send e-mail. I >> >>>would like to write the code test-first as much as >> >>possible. However, I >> >>>notice that that Java Mail API makes heavy use of >> >>static methods to >> >>>accomplish many of its tasks. I see that there >> >>are Mock implementations >> >>>of things like Transport and Message in the Mock >> >>Objects library, but >> >>>I'm not sure how to make use of them. Are there >> >>any simple examples of >> >>>using the MockObjects library to test things that >> >>use things like >> >>>javax.mail.Transport (and related classes?) >>> >>>Thanks. >>> >> >> >> >> > ------------------------------------------------------- > >>This sf.net email is sponsored by:ThinkGeek >>Welcome to geek heaven. >>http://thinkgeek.com/sf >>_______________________________________________ >>Mockobjects-java-users mailing list >>Moc...@li... >> > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users > > > ===== > Griffin Caprio > "Your child against mine. The winner > will be hailed, the loser will be booed > until my throat hurts!" - Homer Simpson to Marge > > __________________________________ > Do you Yahoo!? > The New Yahoo! Search - Faster. Easier. Bingo. > http://search.yahoo.com |
From: Jeff M. <je...@mk...> - 2003-04-30 11:52:42
|
The mocks for Transport/Message etc are mocks of the alt.javax interfaces. Which have both mock and real implementations. The real implementations being wrappers around the javax.mail.* classes. http://www.mockobjects.com/javadoc/1.3/alt/javax/mail/package-summary.html On Tue, 2003-04-29 at 19:40, James Howe wrote: > I'm writing a small utility class which will be used to send e-mail. I > would like to write the code test-first as much as possible. However, I > notice that that Java Mail API makes heavy use of static methods to > accomplish many of its tasks. I see that there are Mock implementations of > things like Transport and Message in the Mock Objects library, but I'm not > sure how to make use of them. Are there any simple examples of using the > MockObjects library to test things that use things like > javax.mail.Transport (and related classes?) > > Thanks. -- Jeff Martin <je...@mk...> |
From: Griffin C. <gri...@ya...> - 2003-04-29 19:50:47
|
Steve, Can you expand on what a "mock mail provider" entails? -Griffin --- Steve Freeman <st...@m3...> wrote: > One option I considered, but never got around to, > was to implement and > register a mock mail provider. > > S. > > James Howe wrote: > > I'm writing a small utility class which will be > used to send e-mail. I > > would like to write the code test-first as much as > possible. However, I > > notice that that Java Mail API makes heavy use of > static methods to > > accomplish many of its tasks. I see that there > are Mock implementations > > of things like Transport and Message in the Mock > Objects library, but > > I'm not sure how to make use of them. Are there > any simple examples of > > using the MockObjects library to test things that > use things like > > javax.mail.Transport (and related classes?) > > > > Thanks. > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-users mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users ===== Griffin Caprio "Your child against mine. The winner will be hailed, the loser will be booed until my throat hurts!" - Homer Simpson to Marge __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com |
From: Steve F. <st...@m3...> - 2003-04-29 19:40:32
|
One option I considered, but never got around to, was to implement and register a mock mail provider. S. James Howe wrote: > I'm writing a small utility class which will be used to send e-mail. I > would like to write the code test-first as much as possible. However, I > notice that that Java Mail API makes heavy use of static methods to > accomplish many of its tasks. I see that there are Mock implementations > of things like Transport and Message in the Mock Objects library, but > I'm not sure how to make use of them. Are there any simple examples of > using the MockObjects library to test things that use things like > javax.mail.Transport (and related classes?) > > Thanks. > |
From: James H. <jw...@al...> - 2003-04-29 18:41:49
|
I'm writing a small utility class which will be used to send e-mail. I would like to write the code test-first as much as possible. However, I notice that that Java Mail API makes heavy use of static methods to accomplish many of its tasks. I see that there are Mock implementations of things like Transport and Message in the Mock Objects library, but I'm not sure how to make use of them. Are there any simple examples of using the MockObjects library to test things that use things like javax.mail.Transport (and related classes?) Thanks. -- James Howe |
From: James H. <jw...@al...> - 2003-04-29 17:35:04
|
Ok, I was wondering whether the problem was with my configuration or because the mock code wasn't up to date with the latest stuff. I'll probably just either stub out the missing methods, or revert to using a different J2EE. Thanks. On 29 Apr 2003 18:12:44 +0100, Jeff Martin <je...@mk...> wrote: > I think you probably the first person to start looking at using the > mocks with J2EE1.4. There's probably some new stuff in the 1.4 which > we've not got methods for. > > The thing to do would be to implemented the missing methods as simply as > possible, so you probably should just call notImplemented(); in each > one. This will get things compiling. If there's any new methods which > need mocking we can descuss them as you go. > > > On Tue, 2003-04-29 at 16:49, James Howe wrote: >> I'm trying to build the MockObjects library using Eclipse. I've been >> able to get the Ant script to build sucessfully, but now I'm trying to >> get the library to build with the standard Eclipse builder. Since I'm >> only interested in a subset of Mock functionality (JDK 1.4, J2EE1.4, >> etc) I've configured Eclipse to only look at a subset of the source >> files available. Most of the files build successfully, but a handful of >> them (all in J2EE/Common) have compile errors. All of the compile >> errors have to do with classes which don't implement all the methods in >> an interface. For example, Eclipse complains about >> com.mockobjects.jms.MockConnection not implemented three methods defined >> in the Connection interface. I'm wondering if anyone has tried to build >> a subset of the MockObjects library using Eclipse and could tell me if >> they have seen this sort of thing before. I'm wondering if I'm just >> using the wrong J2EE jar file, but the one I'm using came from the >> Java(TM) 2 SDK, Enterprise Edition 1.4 Beta release of January, 2003. >> Any information on clearing up this matter would be greatly appreciated. >> >> Thanks. -- James Howe |
From: Jeff M. <je...@mk...> - 2003-04-29 17:10:58
|
I think you probably the first person to start looking at using the mocks with J2EE1.4. There's probably some new stuff in the 1.4 which we've not got methods for. The thing to do would be to implemented the missing methods as simply as possible, so you probably should just call notImplemented(); in each one. This will get things compiling. If there's any new methods which need mocking we can descuss them as you go. On Tue, 2003-04-29 at 16:49, James Howe wrote: > I'm trying to build the MockObjects library using Eclipse. I've been able > to get the Ant script to build sucessfully, but now I'm trying to get the > library to build with the standard Eclipse builder. Since I'm only > interested in a subset of Mock functionality (JDK 1.4, J2EE1.4, etc) I've > configured Eclipse to only look at a subset of the source files available. > Most of the files build successfully, but a handful of them (all in > J2EE/Common) have compile errors. All of the compile errors have to do > with classes which don't implement all the methods in an interface. For > example, Eclipse complains about com.mockobjects.jms.MockConnection not > implemented three methods defined in the Connection interface. I'm > wondering if anyone has tried to build a subset of the MockObjects library > using Eclipse and could tell me if they have seen this sort of thing > before. I'm wondering if I'm just using the wrong J2EE jar file, but the > one I'm using came from the Java(TM) 2 SDK, Enterprise Edition 1.4 Beta > release of January, 2003. > Any information on clearing up this matter would be greatly appreciated. > > Thanks. -- Jeff Martin <je...@mk...> |
From: James H. <jw...@al...> - 2003-04-29 15:50:16
|
I'm trying to build the MockObjects library using Eclipse. I've been able to get the Ant script to build sucessfully, but now I'm trying to get the library to build with the standard Eclipse builder. Since I'm only interested in a subset of Mock functionality (JDK 1.4, J2EE1.4, etc) I've configured Eclipse to only look at a subset of the source files available. Most of the files build successfully, but a handful of them (all in J2EE/Common) have compile errors. All of the compile errors have to do with classes which don't implement all the methods in an interface. For example, Eclipse complains about com.mockobjects.jms.MockConnection not implemented three methods defined in the Connection interface. I'm wondering if anyone has tried to build a subset of the MockObjects library using Eclipse and could tell me if they have seen this sort of thing before. I'm wondering if I'm just using the wrong J2EE jar file, but the one I'm using came from the Java(TM) 2 SDK, Enterprise Edition 1.4 Beta release of January, 2003. Any information on clearing up this matter would be greatly appreciated. Thanks. -- James Howe |
From: Jeff M. <je...@mk...> - 2003-04-29 08:32:14
|
Since MockStatement can now be setup with a list of return values for executeUpdate, executeQuery and execute you don't need count the execute calls as the lists will throw errors if you try to call executeXXX to many or too few times. I didn't think there was much point in deprecating it as in order to get the tests to pass you need to setup the return lists anyways. On Mon, 2003-04-28 at 20:08, James Howe wrote: > I had written some tests using the 0.07 release of the library. Recently > there have been some changes to the SQL related portions of the library > which help in writing database tests where a statement needs to return > multiple result sets. I access the CVS repository and did a build to > create a 0.08 release. When I tried to use it with my existing code I > found that much of the SQL related code had changed substantially. For > example, there used to be a method on MockStatement called > "setExpectedExecuteCalls". This method doesn't seem to exist any more. > I'm curious as to why. Is there some other mechanism which has taken its > place? Was this method considered to be not very useful? > > Thanks. -- Jeff Martin <je...@mk...> |
From: James H. <jw...@al...> - 2003-04-28 19:09:52
|
I had written some tests using the 0.07 release of the library. Recently there have been some changes to the SQL related portions of the library which help in writing database tests where a statement needs to return multiple result sets. I access the CVS repository and did a build to create a 0.08 release. When I tried to use it with my existing code I found that much of the SQL related code had changed substantially. For example, there used to be a method on MockStatement called "setExpectedExecuteCalls". This method doesn't seem to exist any more. I'm curious as to why. Is there some other mechanism which has taken its place? Was this method considered to be not very useful? Thanks. -- James Howe |
From: Steve F. <st...@m3...> - 2003-04-23 22:51:56
|
Alternatively, wrap File in a very shallow decorator that describes the behaviour you want in terms of your domain. Then provide mock and real implementations of that decorator. S. Jeff Martin wrote: > Probably the thing to do whould be to change the alt.java.io.File > interface to use a alt.java.io.FileFilter instead of java.io.FileFilter > which would use alt.java.io.File instead of java.io.File > > On Tue, 2003-04-22 at 22:49, Chris Sterritt wrote: > >>Hello, >> >> I'd like to be able to use MockObjects with a fairly complicated >>FileFilter-implementing class. In particular, I'd like to be able to set >>up a pseudo-directory tree (thanks to MockFile) and then verify that everything >>found is as it should be. However, I find that the class I want to test can't >>take a File as an argument to the method that searches the directory, because >>then I can't use a MockFile (similarly, the FileFilter-implementing >>class can't have an accept(MockFile mf) since that doesn't fulfil the >>interface). >> >> Is the right thing to have two versions of each method, or to implement >>some interface (MyFile) with a class that delegates to a real File in real >>code, and a MockFile in testing? >> >> Thanks, >> --chris sterritt >> >> >> >> >> >> >>------------------------------------------------------- >>This sf.net email is sponsored by:ThinkGeek >>Welcome to geek heaven. >>http://thinkgeek.com/sf >>_______________________________________________ >>Mockobjects-java-users mailing list >>Moc...@li... >>https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users |
From: Jeff M. <je...@mk...> - 2003-04-23 11:55:16
|
Just check in some changes which should help. On Tue, 2003-04-22 at 15:33, James Howe wrote: > I guess my preference would be the latter since it more tightly bonds the > expectation with the type of call that will be made on the statement. > > > On 22 Apr 2003 11:41:12 +0100, Jeff Martin <je...@mk...> wrote: > > > Your probably correct that the MockStatement should be configurable to > > expect multiple query strings. > > > > [...] > > Although all the executes do have a return type so it might be okay to > > have > > > > addExpectedQueryStringAndReturn(String query, ResultSet resultSet) > > addExpectedQueryStringAndReturn(String query, int returnValue) > > addExpectedQueryStringAndReturn(String query, boolean returnValue) > > > > But then again is it better to have. > > > > addExpectedExecuteQueryStringAndReturn(String query, ResultSet > > resultSet) > > addExpectedExecuteUpdateAndReturn(String query, int returnValue) > > addExpectedExectuteAndReturn(String query, boolean returnValue) > > > > How would you ideally like to use it? > > > > > > On Mon, 2003-04-21 at 21:13, James Howe wrote: > >> I'm writing a test of a method which needs to make two SQL queries to > >> get the result. [...] -- Jeff Martin <je...@mk...> |
From: Jeff M. <je...@mk...> - 2003-04-23 09:10:14
|
Probably the thing to do whould be to change the alt.java.io.File interface to use a alt.java.io.FileFilter instead of java.io.FileFilter which would use alt.java.io.File instead of java.io.File On Tue, 2003-04-22 at 22:49, Chris Sterritt wrote: > Hello, > > I'd like to be able to use MockObjects with a fairly complicated > FileFilter-implementing class. In particular, I'd like to be able to set > up a pseudo-directory tree (thanks to MockFile) and then verify that everything > found is as it should be. However, I find that the class I want to test can't > take a File as an argument to the method that searches the directory, because > then I can't use a MockFile (similarly, the FileFilter-implementing > class can't have an accept(MockFile mf) since that doesn't fulfil the > interface). > > Is the right thing to have two versions of each method, or to implement > some interface (MyFile) with a class that delegates to a real File in real > code, and a MockFile in testing? > > Thanks, > --chris sterritt > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-users mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users -- Jeff Martin <je...@mk...> |
From: Chris S. <cst...@sd...> - 2003-04-22 21:50:33
|
Hello, I'd like to be able to use MockObjects with a fairly complicated FileFilter-implementing class. In particular, I'd like to be able to set up a pseudo-directory tree (thanks to MockFile) and then verify that everything found is as it should be. However, I find that the class I want to test can't take a File as an argument to the method that searches the directory, because then I can't use a MockFile (similarly, the FileFilter-implementing class can't have an accept(MockFile mf) since that doesn't fulfil the interface). Is the right thing to have two versions of each method, or to implement some interface (MyFile) with a class that delegates to a real File in real code, and a MockFile in testing? Thanks, --chris sterritt |
From: James H. <jw...@al...> - 2003-04-22 14:35:00
|
I guess my preference would be the latter since it more tightly bonds the expectation with the type of call that will be made on the statement. On 22 Apr 2003 11:41:12 +0100, Jeff Martin <je...@mk...> wrote: > Your probably correct that the MockStatement should be configurable to > expect multiple query strings. > > [...] > Although all the executes do have a return type so it might be okay to > have > > addExpectedQueryStringAndReturn(String query, ResultSet resultSet) > addExpectedQueryStringAndReturn(String query, int returnValue) > addExpectedQueryStringAndReturn(String query, boolean returnValue) > > But then again is it better to have. > > addExpectedExecuteQueryStringAndReturn(String query, ResultSet > resultSet) > addExpectedExecuteUpdateAndReturn(String query, int returnValue) > addExpectedExectuteAndReturn(String query, boolean returnValue) > > How would you ideally like to use it? > > > On Mon, 2003-04-21 at 21:13, James Howe wrote: >> I'm writing a test of a method which needs to make two SQL queries to >> get the result. [...] -- James Howe |
From: Jeff M. <je...@mk...> - 2003-04-22 10:39:49
|
Your probably correct that the MockStatement should be configurable to expect multiple query strings. The best work around would be to actually make a change to the MockStatement so that setExpectedQueryString(String queryString) becomes addExpectedQueryString(String queryString) and myQueryString changes from an ExpectationValue to an ExpectationList. We might want to take things furthur and use the ReturnObjectBag to associate a query with a resultset, but I'm not 100% about this as the Statement interface allows calls to be made to executeUpdate which does not have a ResultSet. Although all the executes do have a return type so it might be okay to have addExpectedQueryStringAndReturn(String query, ResultSet resultSet) addExpectedQueryStringAndReturn(String query, int returnValue) addExpectedQueryStringAndReturn(String query, boolean returnValue) But then again is it better to have. addExpectedExecuteQueryStringAndReturn(String query, ResultSet resultSet) addExpectedExecuteUpdateAndReturn(String query, int returnValue) addExpectedExectuteAndReturn(String query, boolean returnValue) How would you ideally like to use it? On Mon, 2003-04-21 at 21:13, James Howe wrote: > I'm writing a test of a method which needs to make two SQL queries to get > the result. I can configure a MockStatement to return two different > results, but as far as I can tell, I can't set two expected query values. > It seems that if a MockStatement can return multiple result sets, you > should be able to associate a specific expected query value with a > particular result set. In my case, I have a query which gets a count of > something and then uses that count as part of the next query. I would like > to test that the count query was correct and also test that the second > query was correct. Has anyone run into this problem before, and if so, > how did you get around it? > > Thanks. -- Jeff Martin <je...@mk...> |
From: <ric...@vo...> - 2003-04-22 06:20:50
|
Hi James, I am no expert on mock objects testing, I can only tell how I implemented a workaround. I am not happy with the 'solution', so please comment. I implemented the two sql queries in two methods/classes. If method-query 'A' depends on 'B', generate a mock object for 'B' that is used in 'A'. Use the mock object in the test for 'A' and you're done. This implies that a method only could do one sql query, which is weird and has a big impact on the design. Another developer suggested to solve those issues in the database (stored procedures / views / functions), which was also a solution in another project. I am not very good in database programming, but in our team there is lots of experience. In short: I don't have the answer ;-) Richard den Adel. > -----Original Message----- > From: James Howe [mailto:jw...@al...] > Sent: Monday, April 21, 2003 10:13 PM > To: moc...@li... > Subject: [MO-java-users] Question about MockStatement and > expected query > strings > > > I'm writing a test of a method which needs to make two SQL > queries to get > the result. I can configure a MockStatement to return two different > results, but as far as I can tell, I can't set two expected > query values. > It seems that if a MockStatement can return multiple result sets, you > should be able to associate a specific expected query value with a > particular result set. In my case, I have a query which gets > a count of > something and then uses that count as part of the next query. > I would like > to test that the count query was correct and also test that > the second > query was correct. Has anyone run into this problem before, > and if so, > how did you get around it? > > Thanks. > > -- > James Howe > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-users mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users > |
From: James H. <jw...@al...> - 2003-04-21 20:14:37
|
I'm writing a test of a method which needs to make two SQL queries to get the result. I can configure a MockStatement to return two different results, but as far as I can tell, I can't set two expected query values. It seems that if a MockStatement can return multiple result sets, you should be able to associate a specific expected query value with a particular result set. In my case, I have a query which gets a count of something and then uses that count as part of the next query. I would like to test that the count query was correct and also test that the second query was correct. Has anyone run into this problem before, and if so, how did you get around it? Thanks. -- James Howe |
From: James H. <jw...@al...> - 2003-04-18 13:39:53
|
Ok, here's an example of what I ran into yesterday. First, I have a class which has a method on it to return the count of a specific query. The code to do the count looks like this: public int regionCount() throws SQLException { int regionCount = 0; Statement statement = databaseConnection.createStatement(); final String query = regionCountSQLPrefix() + regionCountCountryClause() + REGION_COUNT_SQL_POST; ResultSet results = statement.executeQuery(query); if (results.next()) regionCount = results.getInt(1); statement.close(); return regionCount; } I wrote a test to test this method. First I created the setup method: public void setUp() { mockConnection = new MockConnection(); mockStatement = new MockStatement(); mockConnection.setupStatement(mockStatement); workbench = new CreditGradesWorkbench(countryCodes, mockConnection); } then the test method itself: public void testRegionCount() throws SQLException { final Integer[] resultObject = { new Integer(REGION_COUNT) }; final CommonMockSingleRowResultSet mockResultSet = new MockSingleRowResultSet(); mockResultSet.addExpectedIndexedValues(resultObject); mockConnection.setExpectedCreateStatementCalls(1); mockStatement.setExpectedExecuteCalls(1); mockStatement.setExpectedCloseCalls(1); mockStatement.addResultSet(mockResultSet); mockStatement.setExpectedQueryString(expectedRegionCountQueryString()); int result = workbench.regionCount(); assertEquals(REGION_COUNT, result); mockStatement.verify(); mockConnection.verify(); } I have another method in my class which returns a value from a query, where part of the query uses the regionCount returned by the other method. This method looks like this: public double regionCreditGradeForPercentile(int percentile, int regionCount) { try { int regionCount = regionCount(); double creditGrade = 0.0; Statement statement = databaseConnection.createStatement(); final String query = regionCreditGradeSQLPrefix() + regionCountCountryClause() + REGION_COUNT_SQL_POST + " limit " + percentileCount(percentile, regionCount); ResultSet results = statement.executeQuery(query); if (results.next()) creditGrade = results.getDouble(1); statement.close(); return creditGrade; } catch (SQLException e) { // log something here return Double.NaN; } } Where I ran into trouble was when I tried to write the test for this method. Originally the test method looked like this: public void testRegionCreditGradeForPercentile() { final Double[] resultObject = { new Double(CREDITGRADE) }; final CommonMockSingleRowResultSet mockResultSet = new MockSingleRowResultSet(); mockResultSet.addExpectedIndexedValues(resultObject); mockConnection.setExpectedCreateStatementCalls(1); mockStatement.setExpectedExecuteCalls(1); mockStatement.setExpectedCloseCalls(1); mockStatement.addResultSet(mockResultSet); mockStatement.setExpectedQueryString(baseExpectedRegionCreditGradeQueryString() + " limit " + workbench.percentileCount(10, REGION_COUNT)); double result = workbench.regionCreditGradeForPercentile(10); assertEquals(CREDITGRADE, result, 0.001); mockStatement.verify(); mockConnection.verify(); } However the test failed because the expected query did not match the real query. The problem with my setup is that the method I'm calling, regionCreditGradeForPercentile, makes a call internally to the regionCount method. The region count method needs the statement setup to return the REGION_COUNT value, this value is then appended to the query used by the regionCreditGradeForPercentile which does another query and should return the CREDITGRADE value as the result. Is this just a matter of making sure that I add the value that the regionCount method would return to the result set before adding the value that the regionCreditGradeForPercentile method returns? I assume I would also have to change the values on the number of expected execute calls, close calls, etc. The issue I have is I want to do things once and only once, but I also want to keep things simple. I want to be able to set up the test environment for the regionCreditGradeForPercentile without having to dive into the details of the regionCount method that it invokes. Besides, then I feel like I'm testing regionCount twice. I could redesign the regionCreditGradeForPercentile method to take both the percentile value and a regionCount, but that doesn't quite feel right either. Like I said in my original message, I'm just trying to get a feel for the best way to write tests for code which accesses information in a database. Currently (in another project) we have unit tests for code which actually goes to the database to retrieve information. In most cases I'm sure that a real database wouldn't be necessary, but I'm sure we would need to redesign to make the code more testable. I'm just looking for any best practices that people may have developed for this sort of thing. (BTW, I did read the document on www.mockobjects.com concerning JDBC testing) Thanks. On Fri, 18 Apr 2003 09:41:37 +0100, Steve Freeman <st...@m3...> wrote: > First the simple bit. Assuming you're using the same statement object, > you can just add another result set to be returned. > > I'm not quite sure what you're unhappy about with the test. Could you > post an example of the sort of test you want to write? The short answer > is that this sort of testing tends to push you towards writing smaller, > more focussed classes and methods which some of us believe is a Good > Thing. > > S. > > James Howe wrote: >> I'm just starting to experiment with using MockObjects to test classes >> which access a database. I have some simple methods which I've been >> able to test, but now I'm trying to test some more complicated methods. >> In particular I'm testing a method which uses another method to get a >> result which is then input into a second query. [...] > -- James Howe |
From: Steve F. <st...@m3...> - 2003-04-18 08:41:03
|
First the simple bit. Assuming you're using the same statement object, you can just add another result set to be returned. I'm not quite sure what you're unhappy about with the test. Could you post an example of the sort of test you want to write? The short answer is that this sort of testing tends to push you towards writing smaller, more focussed classes and methods which some of us believe is a Good Thing. S. James Howe wrote: > I'm just starting to experiment with using MockObjects to test classes > which access a database. I have some simple methods which I've been > able to test, but now I'm trying to test some more complicated methods. > In particular I'm testing a method which uses another method to get a > result which is then input into a second query. It looks something like > this (a rough approximation of the algorithm): > > public double value() { > int count = fullCount(); // this method peforms a count(*) type of > query > String query = "blah blah blah limit " + (count * .30); > mockResults = mockStatement.executeQuery(query); > if (mockResults.next()) > return mockResults.getDouble(1); > return Double.NaN; > } > > The problem is testing this method. I'm doing two different queries so > I need to get two different result sets. I'm sure I can come up with > some way to handle this, but I'm wondering if there is a general pattern > for handling this sort of thing? What bothers me is that in order to > test my "value" method, I also have to know how to set up the > environment to support methods that the method might call, and so on > down the line. Is there a better way to organize my database code which > might avoid this problem? > > Thanks. > > -- "A LISP programmer knows the value of everything but the cost of nothing. A C programmer knows the cost of everything but the value of nothing." (Todd Proebsting) |
From: James H. <jw...@al...> - 2003-04-17 23:17:13
|
I'm just starting to experiment with using MockObjects to test classes which access a database. I have some simple methods which I've been able to test, but now I'm trying to test some more complicated methods. In particular I'm testing a method which uses another method to get a result which is then input into a second query. It looks something like this (a rough approximation of the algorithm): public double value() { int count = fullCount(); // this method peforms a count(*) type of query String query = "blah blah blah limit " + (count * .30); mockResults = mockStatement.executeQuery(query); if (mockResults.next()) return mockResults.getDouble(1); return Double.NaN; } The problem is testing this method. I'm doing two different queries so I need to get two different result sets. I'm sure I can come up with some way to handle this, but I'm wondering if there is a general pattern for handling this sort of thing? What bothers me is that in order to test my "value" method, I also have to know how to set up the environment to support methods that the method might call, and so on down the line. Is there a better way to organize my database code which might avoid this problem? Thanks. -- James Howe |
From: Griffin C. <gri...@ya...> - 2003-04-14 00:35:39
|
Hello all! This is a announcement of the new DotNetMock has been released, version 0.4. Below is the change log: MockObject.cs - Marked Fail(), AssertTrue(), AssertEquals() Obsolete MockObject.cs - Added MockName Property for name variable MockObject.cs - Changed to implement IMockObject interface NullObject.cs - Added Name property for name variable IMockObject.cs - Added IMockObject interface for custom MockObjects MockDataReader.cs - Fixed indexing bug MockDataParameterCollection - Fixed Verify() bug AbstractExpectationCollection.cs - Fixed ClearActual() bug. was really ClearExpected() MockDbConnection.cs - State, ConnectionTimeout, & Command setups were fixed MockXPathNodeIterator.cs - Added XPathNodeIterator MockXPathDocument.cs - Added XPathDocument MockXPathNodeIterator.cs - Added XPathNodeIterator IMockObject.cs - Changed className to methodName in NotImplemented() MockXPathNavigator.cs - Added XPathNavigator Added VisualStudioTemplates for C# MockDataParameterCollection.cs - Changed Verify() method to not fail for no expected parameters. ExpectationCounter.cs - Changed Verify() method to only Verify if the object HasExpectations Plus other minor fixes.... Check it out if you get a chance and throw some feedback my way if you get a chance. Thanks, Griffin ===== Griffin Caprio "Your child against mine. The winner will be hailed, the loser will be booed until my throat hurts!" - Homer Simpson to Marge __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com |