Aug 25 2008

jUnit 4.x Test Suites…

Category: Java,TestingPhil @ 8:11 pm

Have you ever wanted to run all of your jUnit tests from within Eclipse? It is pretty easy if they are in the same package, but if you have a hierarchy of packages, you are out of luck! I learned quite a few jUnit tricks tonight, even found the exact code I was looking for. You can read about some annotation-based test suites at this site. This guy gave me the exact code I was looking for, maybe someday they will add this feature directly to jUnit!

I’m still digging Unitils as well… I found a cool annotation to rollback the transaction for a specific test case. This is kind of nice when you don’t want your jUnits messing up your database! Check this out…

@Test
@Transactional(TransactionMode.ROLLBACK)
public void validateLoad() {…}

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


Nov 01 2007

Log4JDBC, A Sybase Logging Experiment

Category: JavaPhil @ 8:19 pm

Sybase jConnect 6.0 comes with several examples and I kind of thought this debugging example might prove valuable. The main goal of this exercise was to get parameter substitution working when queries are envoked to simplify debugging via logging. It looked like it could be promising from the documentation, and it was very easy to setup, provided you had the jconn3d.jar.

final String url = "jdbc:sybase:Tds:localhost:5003/database";
final String classes = "SybConnection:SybStatement:Debug:STATIC";
final SybDriver sybDriver = (SybDriver) DriverManager.getDriver(url);
final Debug logger = sybDriver.getDebug();
logger.debug(true, classes);

The debug library produced lots of information about what was happening, unfortunately, it was very chatty and not very descriptive; it printed out conversion and type information, but as codes rather than the “readible” values, and the worst part was that none values were displayed.

com.sybase.jdbc3.jdbc.SybConnection(Thread[main,5,main]): autocommit state is: true
com.sybase.jdbc3.jdbc.SybConnection(Thread[main,5,main]): initProtocol()
(Thread[main,5,main]): processEscapes( {call STP1(?, ?, ?, ?, ?)} )
(Thread[main,5,main]): converted buffer = 'STP1 ?, ?, ?, ?, ?, ?'
(Thread[main,5,main]): numString(5) --> 5
(Thread[main,5,main]): dataTypeInfo Param: 12, converted to TDS type 39, length = 9
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 4
(Thread[main,5,main]): dataTypeInfo Param: 12, converted to TDS type 39, length = 9
(Thread[main,5,main]): dataTypeInfo Param: 12, converted to TDS type 39, length = 32
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 0
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 0
(Thread[main,5,main]): dataTypeInfo Param: 1, converted to TDS type 39, length = 0
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 0

Another really nice option seems to be the log4jdbc
library. It is also very easy to use; just change a couple JDBC
configuration properties. It actually provided all of the information
we were looking for and quickly integrated with our Spring and
Hibernate environment. It was highly configurable, and one of the
nicest things was that it would actually provide “timings” on all of
the executed sql. The seems like a really good tool to use during
development and testing, not sure if I would run it in a production
environment; I guess it depends on the requirements of the system.

FINE 10/29/2007 09:58:33 AM [Slf4jSpyLogDelegator.sqlTimingOccured()][main]
org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
2. {STP_Name('111129922', '5', '144808258', 'DM043BD4C600006EDC00000001 ', <out>, <out>,
<out>,<out>,<out>,<out>,<out>,<out>,<out>,<out>,<out>,<out>,, )} {executed in 79 msec}

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


Oct 31 2007

Crap4J

Category: Java,TestingPhil @ 7:27 pm

Everyone knows that I’m always preaching about code quality and testing, and yesterday I was reading something on the web that I just thought was just too funny. There is actually an Eclipse plug-in called crap4j. It provides a metric to identify code which is difficult to understand, test, or maintain. CRAP actually stands for Change Risk Analysis and Predictions. Here was an interesting blog on CRAP. I have not had the time to read more about this metric, but I like tools that help provide feedback to developers, in my opinion, these tools only help us write better code, and seldom get in the way. The biggest problem is usually getting the team to buy into them. Hopefully, I will have some time to learn about this metric and actually try the plug-in; but with the name and logo like they selected, how can it be bad?

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


« Previous Page