Using UI tests in Continuous Testing - java

I am planning to write some UI tests for a legacy Java EE application. Can anyone with similar experience recommend a tool for this? (I am thinking of going ahead with Selenium). Also do you recommend putting these tests as a part of the CD pipeline (my concern is because they are usually a little fragile)? (It will be great if you guys could share some strategies e.g. part with CD part as a separate daily regression)
Thanks

Try this as a good pointer. Re-think your approach!
http://googletesting.blogspot.co.uk/2015/04/just-say-no-to-more-end-to-end-tests.html
Also read about the Test Pyramid.
http://martinfowler.com/bliki/TestPyramid.html
Some people will disagree... depends on the calibre of teams you're working with, and the levels of stress they're under to deliver!

Related

What to test with Robolectric?

It seems to me that I am fundamentally misunderstanding the purpose of Robolectric. I've been battling with it for a week already, and so far getting a new error message is considered as making progress. I am able to test some basic stuff like static views in an activity, but when something more complicated things come into play things just fall apart. I had to extend Robolectric to support 3-rd party libraries with certain parameters, Appcompat action bars and numerous other things which was extremely time-consuming and wasn't really documented anywhere, and things are advancing at a pretty much glacial pace. I am starting to think that I am using it in a wrong way and it simply isn't supposed to do what I want it to do.
The general app logic is quite straightforward so there isn't really much to unit test, the most complicated stuff is in the UI and remote API calls. Is Robolectric just supposed to make unit testing for Android less painful than with JUnit because it can run on the JVM and supports a few Android classes? Perhaps a black-box behaviour testing framework like Espresso would be more suitable for my needs? But we use continuos integration, and Robolectric was nice and easy to set up to run tests on the CI server, and I'd kind of like to keep it that way.
What do you use Robolectric for? A lot of blog posts recommend it for "activity lifecycle testing", but since I'm also quite new in the Android world, I don't really understand the purpose of it, especially since the app I'm testing is portrait-only. Could someone please give an overview of what you use Robolectric for, and how do you do it, preferably with code examples and explain why and how those tests are important?
We use it for:
unit testing: all components from parsers and utils, to controllers and presenters
integration/acceptance testing: the business logic of the app, per screen (which falls into integration and/or acceptance testing)
We don't use it for (and have found it difficult to use for these):
testing the network layer (we run all tests by injecting the test data in the same way the network layer would; parsers are tested separately)
user flows through different screens
If you're looking for more of the latter, perhaps Espresso/Robotium are better suited for your needs. And you absolutely can run these as part of your CI pipeline, but you'll need to invest some time in setup, or integrating with something like Appurify.
If you are finding it very difficult to write your tests, it might have to do more with the way your app is architected than the way you're using robolectric. See my answer here as well, it might help you: Writing Android acceptance tests with robolectric: how could it be done?

Rapid Test Driven Development in Java

I have been using the guard framework in rails for quiet a while and I have just fallen in love with it. I also work in Java a lot and I find it surprising that such a tool is not available for rapid test driven development. Here's what guard does for you (form the original website)-
File system changes handled by our awesome Listen gem.
Support for visual system notifications.
Huge (more than 120) guard extensions eco-system.
Tested against Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest versions of JRuby & Rubinius.
In essence, it helps me keep an eye on test cases while I am making changes or adding stuff to my codebase. The following are the benefits of such an approach-
Unobtrusive test case driven development
Instant acknowledgement of the impact of a code change
High quality code
Minimized regression ripples
Does anyone know how to achieve similar goals in Java?
Note- Automated test tools like Hudson is not an answer I am looking for. I need something that can be used on local development machines/environment so there is an instant test case feedback on a code change.
Thanks
Not sure what you are looking for ... but if you search for a tool that runs your unit tests in the background during development have a look at Infinitest or JUnit Max.
If you work with eclipse, and you dock your JUnit view in a convenient place, it's one button to click to rerun your tests, and see the report immediately in the same view.
It's a very efficient way to perform test driven developpement.
You could use Sonar with Hudson to do this for you. In the company I work in, we use this combination to solve your issue. There's also a Sonar plugin for Eclipse. But, if you look for something like an IDE-based solution I can't help you.

performance testing for Java Web Application

Is there any easy tool from which we can enter 1000s of data into DB. Actually we have to do some performance testing and improvement in our Java Web Application.
Any help would be appreciated.
Thanks in Advance.
JMeter is a java-based web-application load and stress-testing tool than many people use.
I don't know what your particular stack looks like, but if you are using something like Spring/Hibernate, I have used this small builder pattern library to create (and destroy) mounds of test data to run through JUnit integration type tests very easily:
http://code.google.com/p/make-it-easy/
There is also DBUnit http://www.dbunit.org/ which might do what you want, but I have had less success with it in the kinds of apps I have worked on. It might be just the ticket for your needs, however.

Is it worth changing from java/spring/hibernate to rails for a program that is undergoing massive changes?

I have a project whose core domain is dramatically changing. It's possible to use 50% of the core functionality from this site and just add the 50% new functionality, but I am starting to consider that maybe it might be faster to simply redo the product in Rails. Development speed is very important.
There are some things I really like about java - the performance and scalability are very good. I am not a crappy Java developer, so my apps tend to run very well - better than the Rails sites I've seen. I've always accepted the idea that people probably just throw a little more money at the problem when it comes to using Rails, which probably works itself out in the end because of the insane productivity benefits.
I am actually quite agile with Java. I know it will still take me longer to add a basic entity to the system, but I am quick at it and I don't mind it that much. At least it's easy and straight-forward to do.
What I do mind is:
having to start/stop the server just to fix a route, lazy load exception, controller is going to wrong view, etc.
putting up with the fact that unit/integration tests sometimes have different results than the production environment (because annotations on controllers can't be tested, or lazy-loading exceptions occur during asynchronous service calls, or things like that). Knowing if your Jackson is marshaling your data properly is another Tomcat-only thing because it's handled by Spring. There are lots of things that go wrong after you have tested all that you can, and this frankly annoys the crap out of me.
putting up with the occasional maven/classloader problem that doesn't rear its ugly head until you deploy into tomcat. It gives the false impression that everything is "a-okay" when you are in your IDE.
having to put more effort to do database migrations than the ruby people ever have to.
putting up with framework bugs in Spring that block (it's happened about 5 times on this project since 2009) or Hibernate. I also don't like upgrading Spring Security and having them constantly change the configuration, apis and tag libraries over and over again. This is annoying.
wasting so much time uploading 58 MB war files to the server! These take me 12 minutes to upload whenever I need to deploy changes. If I forgot to do 'mvn clean' before I upload, Spring might complain that 2 beans exist with the same name because I moved one to a new package... and then I have to re-upload the whole stupid war file again. Why isn't "clean" run by default whenever you do 'mvn package' for?!?! Sometimes these frameworks and tools use the stupidest default settings. This is just so common in the Java world.
Having to spend hour(s) to figure out where a framework wants to plug-in your own custom implementation for something. This is very annoying. You can spend 2 hours sifting through Google and crappy documentation trying to figure out how to override Spring Security's authentication mechanism for example... and then spend only 5 minutes writing the actual implementation. Of course, they wrote paragraphs upon paragraphs explaining the architecture and how awesome it is, but nobody cares. For something so common, why not just give example source code and be done with it?
Waiting 10-15 seconds for Spring to start up whenever you want to run your integration tests. This is a drag.
There are a few things I like about Java though. Role-based access is very easy to do with Spring Security. Authentication is never that big of a gain, but I like the implementation inside of Spring.
I also like Spring's form-backing objects and #ModelAttribute. These are huge wins when it comes to controllers, and I don't know if Rails can do these things. I honestly never liked passing request parameters around in every action - Spring MVC is actually a lot easier to use when it comes to this common bloat.
Being able to cache really massive structures in memory and have them stay in memory when you start the application is also highly desirable, especially for this application actually. I have an in-memory thesaurus and grammar checker that needs to get called hundreds of times per request, so in memory is pretty much the fastest option for me.
Even still, I think I could rebuild what I have in 2-3 weeks, and then add all of the new features in a few weeks using rails.
On the bright side, all of the really well-designed css, html and javascript could be ported over with very little problems.
I'd appreciate some advice on the subject before I continue.
PS: I could also go to Spring-ROO... but that would also be a considerable rework. I was never using JPA - I was using Hibernate directly. I am also not using JSP's - I am using Freemarker.
It takes more time to get good at Ruby, and Rails. I worked as an independent contractor as Spring and Hibernate expert myself, but I felt strangled by java and it's web frameworks so I decided to learn Ruby on Rails.
I would advice you to learn Ruby, from what I read you would probably master it, although get pretty frustrated with the very different way the use the ORM. I had issues with it, used to working on aggregate roots in Hibernate to the ActiveRecord one class one table kind of pattern. But hey, you could easily try out MongoDB to have some real fun.
Ruby is
less code
it's fast and scalable (slower than java on the specific tasks, but you get rid of stacks of layers.)
the problems are more often; which gem should I use. Luxorious!
a unique, big, sharing and caring open source community
nice frameworks, as Rails and Sinatra
powerful.
fun!
Would I advice you to do the project you describe in Ruby.
NO.
Not if speed of development matters. You will be slower, trust me. There's a lot to learn, it's conventions are not familiar to a java programmer and when you get stuck, lots of hours fly by.
The best option would be to hire a senior ruby developer to pair up with you and teach you. Be a good apprentice and you'll learn fast. Faster than me, I had to learn most by myself, which is really inefficient.
Good luck!
Check out Playframework. Its fun to develop, and you can use your Java experience to develop features way quicker (given than you have 2 weeks) than any other Java-based frameworks out there.
You do not have to start/stop a server. You fix the code in Eclipse and hit refresh on the browser. No dealing with WAR files till you have to actually deploy in production. Do everything from within Eclipse. Easily perform TDD process if thats what you want as you develop code. From an architecture standpoint, it is a fully stateless, RESTful framework from the get-go. Fully JPA compliant (even for NoSQL like Mongo), so you will not have to write complex JDBC code. On the front-end, it has a full featured templating engine, using Groovy as a templating language.
I can go on and on, but I'd recommend going through the site and take a look.
You should take a look at Grails.
You can continue to leverage a lot of your Java code but use a scripting language (Groovy) and many of the paradigms of Rails. E.g. lots of time saved by using convention rather than configuration.
Grails is used by some pretty big web sites E.g. BSkyB the UK satellite broadcaster.
It doesn't really help with some of the startup speed aspects. If you really prize development speed that much - get a faster machine or buy an SSD and fit in your machine. If you work for a big company - sell it to your manager as the cheaper option (E.g. buy a $2000 machine rather than spend 3 weeks rewriting something to save 10 minutes a day).
Java will scale better in the long run than Rails. The Hotspot technology in the JVM is one of the wonders of modern technology.
Also worth checking out is Tapestry5. It allows you to make code changes on the fly (no server restart required) and is easily the fastest & leanest framework to develop with in Java I've used.
I would still give Spring Roo a shot, it will the same rework as with Ruby on Rails or Grails or even less, but you will still stay with something that you are familiar with, which is often the biggest consideration
It has the scaffolding concepts of Ruby on Rails and Grails, but it gives you zero lock in code, just simple, well written (massive use of AOP is matter of taste though) of Spring + Hibernate / JPA (I think you can use Freemarker for the views, Roo has a miriad of plugins, but I'm not 100% sure)

Understanding large Java Code Base

Are there resources on going about trying to understand a large java code base. Like for example, a graph persistence implementation. If there is minimal / missing documentation, what kinds of approaches do you take ? Are there any books that deal with this ? I know one called Brownfield App Development in .NET.
Perhaps something similar ?
There are number of ways to tackle such a problem and most of the times it will be your personal preference and style of coding and solving problems... for ex:
Start with any documentation/TDD if available.
Use some design/UML tool like EA Architect to generate the UML/Class diagram to understand the class structure.
If the project has some test cases, start by executing and understanding the code behind it.
Try running the application and you can set some debug points and try understanding the flow.
End of the day it all depends on the project, how well the code is documented and your personal style of solving problems.
My suggestions would be:
Get the code building. If there is no build script, write one.
Get the code running.
If there are no tests, start picking off bits of the system to write tests for. You're not really testing, you're learning about the system's behaviour.
Use a modern IDE (Eclipse, Netbeans, etc.) to start tracing the declarations and references to methods and classes.
Good luck!
Ian.
It all depends on how the project is organized. Some ideas off the top of my head:
Look for the core / domain knowledge:
See if domain knowledge is isolated and start from understanding it.
See how the code is split into projects, modules (e.g. jars) and packages. If there is at least some organization, look for the "core" and start learning from there.
Look for other traces of this knowledge: diagrams, tests, documents, samples.
Try running the application. Analyze what happens from the entry points down.
Learn the basic architecture. Look for the familiar ground (frameworks and solutions you know) and see how it is used.
If you want to trace the execution of your Java code to get a feel for the flow of control you can use a tool called InTrace.
NOTE: InTrace is a free and open source tool which I have written.

Categories