Devoxx 2012 – Day 4
Unitils: full stack testing solution for enterprise applications by Thomas de Rycke and Jeroen Horemans
There are different types of test: unit tests (testing in isolation), integration tests (testing a subsystem) and system tests (testing the whole system). The higher you get in the hierarchy, the longer it will to execute, so you should have a lot of UT, some IT and just a few system tests.
Unit tests have to be super fast to execute, be easy to read and refactor, they also should tell you what went wrong without debugging. On the other hand, you’ve to write a lot of tests. Not writing unit tests will get you faster in the first phase, but when the application grows, it will drastically slows your productivity down. In enterprise settings, you’re better off with UT.
In order to avoid an explosion of testing frameworks, Unitils testing framework was chosen. Either JUnit or TestNG can be hooked into Unitils. The core itself is small (so as to be fast), the architecture being based on modules.
Let’s take for example a Greetings Card Sending application. – the demoed code is nicely layered, with service and dao and uses Spring autowiring and transactions through annotations – Unitils is available from Maven, so adding it to your classpath is just a matter of adding the right dep to the POM. Unitils provide some annotations:
@TestedObjectto set on the target object
@Mockto inject the different collaborators (using EasyMock)
@InjectByTypeto hint at the injection strategy for Unitils to use
Even though testing POJOs (as well as DTOs) is not very cost-effective, a single test class can be created to check for JavaBean conventions.
Unit testing becomes trivial if you learn how to write testable code: designing good OO and dependency injection, seams in your code and avoid at all the use of global state (time for example). What about integration and systems? They tend to get complex and you’ll need a “magic” abstract superclass. Moreover, when an IT fails, you don’t know if the code is buggy or if the IT itself is. Besides, you’ll probably need to learn of frameworks (JSF comes with its own testing framework, JSFUnit).
As software developers, the same problems come back:
- Database: is my schema up-to-date? How to manage my referential integritry to set up and tear down data?
- Those operations are probably slow
- Finally, how to deal with external problems?
Unitils provides a solution for each of these problems, through the use of a dedicated module for each. For example, a Webdriver module lets you use Selenium through Unitils, a DBUnit module does the same for DBunit and a Mail module creates a fake SMTP server.
– speakers tells us that with Unitils, there’s no need for a magic abstract superclass anymore: IMHO, it has been replace with a magic black box testing framework –
Unitils benefits from a whole set of modules, which covers a single dedicated area: Swing, Batch, File, Spring, Joda Time,etc.
Modern software development anti-patterns by Martijn Verburg and Ben Evans
There are 10 anti-patterns to cover:
|Anti-pattern||Diabolical programmers||Voice of reason||What to do|
|Conference-Driven Delivery||Real pros hack code and write their slides minutes before their talks||PPPPPP||In order to improve your presentation skills, you can rehearse in front of the mirror. Let’s call it Test-Driven presentations. Begin with a supportive crew, then grow into larger and larger audience.|
|Mortgage-Driven Development||In order for others not to steal your job, don’t do any documentation. Even better, control your source code i.e keep the source on a USB key||Don’t succumb to fear: proper communication is key.||Developers who communicate have the most success. If you want one of your idea to go into source control, you’ll have to communicate about it.|
|Distracted by shiny||Always use the latest tech, it’ll put you ahead. Consider using the latest version of Eclipse, packed full of plugins||Prototype and evaluate: learn to separate the myth from the reality. As an example, web frameworks are an area you should tread carefully.||Code reviews are an asset, especially if everyone do them so as to share best practices.
Brown bag sessions are good, in order to test every possible options.
|Design-Driven Design||UML Code generators are awesome. Print your UML diagrams on gigantic sheets, put them on the wall, and if someone asks you a question, reply that it’s obvious||Design for what you need to know: don’t try to do too much upfront. Successful teams are able to navigate between methodologies that suit them.||Less source code: pay your junior developers to produce code, and pay your senior to remove it. The less code, the less chances to have bugs. Be wary of maintainability, though (Clojure is a good example).|
|Pokemon pattern||Use allof the GoF patterns||The appropriate design pattern is your friend. Using a design pattern is adding a feature to a language which is missing it. As an example, Java concurrency works, but since mutability is deeply rooted, it’s hard. Of course, you could use actors (like in Scala), but you definitely would add a feature.||Whiteboard, whiteboard and whiteboard, to communicate with your colleagues. As a tip, carry whiteboard markers at all time (or alternatively pen and pencil).|
|Tuning by Folklore||Performance tune by lightning black candles. Remove string concatenations, add DB connections and so on||Measure, don’t guess. It’s the best approach to improve performance. If it sounds boring, it’s because it is. Remember that the problem is probably not where you think it is.||Shameless plug: go to jClarity|
|Deity||All the code in one file is easier to search. VB 6 is one of the most popular language because of it||Discrete components based on SOLID principles: Single Responsibility, Open to extension, Litskov substitution, etc.||Discuss with your team, don’t go screaming WTF, you’ll probably have issues. You need to use naming based on the domain model so as other developers can read your code|
|Lean Startup Ninja||A ninja ships its code when it compiles!Continuous delivery is a business enabler.||Tools are available to achieve continuosu delivery: Ant/Gradle/Maven + Jenkins + Puppet + Vagrant|
|CV++||The Tiobe index is your friend.||Just be good at the principles. Try different languages, because when learning another language can be applied to the language you’re currently programming in.||Being a Software Developer is better than a Programmer. The former understands the whole lifecycle of an application, which is much better.|
|I haz Cloud||Nothing can go wrong if you push your applications in the cloud||Evaluate and prototype||There are many providers available: EC2, Heroku, JElastic, CloudBees, OpenShift, etc. Again, a brown bag session is a great way to start|
|Can Haz Mobile||If you go into the mobile game, you’ll be a millionaire|
|HTML5 for the win||UX is so important. What are your UX needs?||Think about what pisses you off…|
|Big Data||MongoDB is web scale||What type of data are you storing?||Non-functional matters. Business doesn’t care about distributed databases, but about their reports!|
Simplicity in Scala Design by Bill Venners
The main thing is to show how to:
- Design to simplify tasks for your users
- Design for busy teams. Don’t assume your users are expert in your libraries. It’s something like driving a car you’ve never driven before: it should be so obvious users shouldn’t have to check the documentation
- Make it obvious, guessable or easy to remember, by order of preference. The choice process for the
plusOrMinusin ScalaTest is a good example.
- Design for readers, then writers, in that order. To choose the name for the
invokePrivateis a good example: better use something semantically significant than some symbol
- Make errors impossible (or difficult at last). In particular, use Scala’s rich type system to achieve this. Using the compiler to flag errors is the best
- Exploit familiarity. James Gosling used familiar C++ keywords in Java, but without memory management so as to leverage this principle. So is the way ScalaTest is using JUnit constructs but enforcing a label on each test.
- Document with examples
- Minimize redudancy. A Zen of Python states:
“There should be one and preferably only one obvious way to do it.”
. A good practice would be to put a Recommended Usage blocks for each class.
- Maximize consistency. ScalaTest offers a
GivenWhenThentrait as well as the
Suiteclass. But when you mixin the latter with the former, you do not need to set the name of the test. However, enforcing the Single Responsibility Principle and introducing
Specsolves the problem.
- USe symbols when your users are already experts in them. Scala provides
multiply. On the contrary, in SBT some symbols prove to be problematic:
<<++=. Likewise, it’s better to use
/:. However, there are situations where you shouldn’t be able to use words at all (like in algebra).
- Use a functional style by default, but switch to an imperative style where it improves usability. For example,
testfunctions in a suite, it registers the tests typed inside the braces.
Remember what tools are for. They are for solving problems, not finding problems to solve
Re-imagining the browser with AngularJS by Igor Minar and Misko Hevery
– I attend this session in order to open my mind about HATEOAS applications. I so do hope it’s worth it! –
Browsers were really simple at one time. 16 years later, browsers offer many more features, going as far as allowing people to develop through a browser! For a user, this is a good, for a developer not so much because of complexity.
AngularJS takes care of this now, while a specification is under work for this should be part of how browser works. HTML can be verbose, tabs are a good example: they currently use
div while they should be using
tab. From a more general point-of-view, AngularJS brings such components to the table. Also, the Web Components is an attempt at standardization of this feature.
– here comes a demo –
AngularJS works by importing the needed js files, creating a module in JS and adding custom attribute to HTML tags.
Apache TomEE, JavaEE 6 Web Profile on Tomcat by David Blevins
Apache TomEE is trying to solve the problem in that you run with Tomcat unlike you hit the wall and go to another server. TomEE is a certified Web Profile stack, it is a Tomcat with the Apache libraries to bridge the gap. Core values include being small, being certified and stay Tomcat.
What is the Web Profile anyway? In order to solve the bloated image of JavaEE, v6 specs introduced kepping only about half the specs of the full JavaEE specs (12 on 24). Things that are not included:
The last 4 are especially lacking so TomEE comes into 3 flavors: Web Profile including JavaMail (certified), JAX-RS (certified) and Plus which includes JAX-WS, Connector and JMS (not certified). Note that in JavaEE 7 will certainly change those distributions, since profiles themselves will change. TomEE began in 2011 with 1.0.0.beta 1 and October saw the release of 1.5.0. TomEE is know for its performance but also its lack of extended support.
– here comes the TomEE demo, including its integration with Eclipse (which is exactly the same as for Tomcat bare –
TomcatEE is just Tomcat with a couple of JAR in both
endorsed, extra-configuration in
conf and a launcher for each OS in
bin. Also, there’s Java agent (– for some reason I couldn’t catch –).
Testing is done with Arquillian and runs within an hour. Certifications tests are executed on Amazon EC2 instances, each having 613 max memory (and runs in +hundred hours): note that TCK pass with default JVM memory. The result is quite interesting with a 27Mb download, with only 64Mb memory taken at runtime. It would be a bad idea to integrate all stacks yourself, not only because it’s just a waste of time, but also because there’s a gap between aggregating all components individually and the integration that was done in TomEE.
Important features of TomEE include integration of Arquillian and Maven. A key point of TomEE is that deployment errors are printed out all at the same time and do not force you to correct those errors one by one as it’s the case with other application servers.