Writing middle tier tests for website built using Struts - java

I have never done any middle tier testing before and I am brand new to Struts. I was assigned the task to find out if it is possible to do middle tier testing of a Struts website and how to do it if it is. I wonder if anyone has experience writing middle tier tests for a website built using the Java Struts framework. If you do, 1) do you find it difficult to do so/would you recommend to just test the website in the UI level? 2) do you have recommendation of any websites or books I should go to/read to learn how to do so?
In case it helps, the website is using tiles in the UI and hibernate.

First of all, it does not matter what frontend technology you are using, if you want to test your middle tier. It more depends on your system's architecture, e.g. it will be hard to test separately when all your business logic is implemented in Struts Actions.
Please check out Uncle Bob's article "The Test Bus Imperative", where he explains how your applications should be structured to enable middle tier testing.
Furthermore, read Michael Cohn's blog entry about the Testing Pyramid, which should give you a hint of how to structure your automated tests. There you will see to create GUI based tests, but also that those should not be the majority. Additionally, you can get some information about GUI testing here.
So, first locate your actual business logic and than verify how hard it is to test it separately (without clicking around at the GUI). If that is not possible you probably should stick with GUI tests, using e.g. Selenium. Here are some guidelines for doing so without shooting yourself in the foot :)

Related

how to form a framework in selenium driver for web automation where by just passing some metadata, the entire code must be generated

I need knowledge about how to develop a framework for web automation using selenium webdriver. please give me ideas and steps to create framework.
Now I'm able to locate all the web elements on web application by just writing a one big bunch of TestNG test code by using #Test annotation.
In my web application there are many places where I can reuse the code to do the same operation across all. So help me out to develop a best framework.
It depends on the problems you are facing.
If you want to clearly separate writing scenarios from editing the logic (for instance, you work in a team with testers who aren't software engineers but know Java and algorithmic well enough to construct elaborate scenarios from small building blocks), then it would be wise to introduce a layer of steps classes containing methods like openTheUserMenu(), fillTheFormDetails(String name, String surname, String address) etc.
If you write tests for some dynamically changing or developing project with UI elements changed or refactored often you would definitely need Page Object pattern to encapsulate the UI logic (so that in your steps you would write just mainPage.selectDateOnCalendar(Date date), and all the necessary typing and clicking would be written out in the page's method).
Finally, if you work closely with your client and need to formulate the requirements in natural language first, and then translate them into more formalized language for developers to implement the required functionality, you would need to use BDD and appropriate libraries like JBehave with scenarios written in phrases in high-level almost natural language mapped onto test methods in Java.
In short, this is it. If you want details, there are plenty of materials on the Net as was mentioned already. Just remember - you should invest in elaborate framework only if you really need one to solve the problems you are facing.

Hard coding my Selenium scripts in Java

Hi I am very new in Selenium WebDriver and I am at a cross roads right now. I took one module of the application I am working on and wrote the scripts for it. I ended up with a lot of java classes. Now,
How do I incorporate that into the framework?
Am I doing the right thing?
Is it advisable to hard code everything before incorporating it into the framework?
Please help, your input will make a huge difference. Thank you!!!
You have done correct thing since you are new to selenium. The next step is to create a very basic framework that can support keyword or data driven approach. You can also go for page object model or page pattern using factory. Again you have to evaluate those frameworks with respect to your project complexity and pick the correct one and develop.
Hard coding things are not good, you need to try to get rid of hard coding ASAP otherwise tests will not be manageable as test suits grows.
A good test automation framework should have minimum following capability:
Scope of code re-usability using helper classes
Capable of logging information
Modular
Data driven.
If you want, keyword driven
Well formatted object repository.
Choose a good unit testing framework and use it.
Hope this information will help you.

What is the exactly use of Robot framework?

I'm fascinated towards robots. You know usually it creates our work easy and for web you don't need to go anywhere on links once our robots is initialized on web server.
Let's come to our main question:
What exactly is the use of Robot Framework .. I'm good with Java but not with Python. Can I use it with Java? For what purpose Robot Framework is used for?
I'm good in HTMLUnit. But it can be used to parse the HTML source code and we could also implement it in Java to make source code. But what about Robot Framework?
I googled for 2 hours but couldn't find the exact answers. Please let me know if you want to know any information from me.
Overview
It's main use is to enable writing acceptance tests with a high level of abstraction for software products.
The framework requires less technical skill than programming language-based frameworks, and so can be used by team members who have very little programming experience. For example, an agile team product owner could express acceptance tests using the framework, without having to know the details of how the product is implemented.
On the other hand, because of its keyword-based design, those with a high degree of technical skill can write keywords in their language of choice to test low level functions, and even do unit and integration testing if so desired.
Uses
Because of its flexibility, robot framework can be used to test desktop applications, web applications, mobile applications, and RESTful and SOAP-based services. Because it provides an abstraction layer on top of the physical implementation of the system under test, it is possible to write tests that work cross-platform (ie: the same test case could be used to test both an android and iOS app, or for testing a web app that runs on chrome, firefox and safari).
Although robot framework is often used to test browser-based applications, it has been used to test databases, mobile devices, calculators, and many other things.
Extensibility
One of the great strengths of the robot framework is that it is highly extensible. Many of the features mentioned above are implemented as libraries. For example, you can plug in a library to use selenium to drive a browser. You can plug in a database library to directly access databases. There are libraries to support testing desktop apps, services, and many more.
Example
To illustrate how abstract a robot test case can be, a BDD-style testcase might look -- literally -- like this:
Given I am on the application login screen
When I enter a valid username and password
And I press the "login button"
Then I should be logged in
And my personal dashboard should be displayed
Note: this isn't the only way to write a test. Robot is very flexible, allowing you to choose between BDD (Behavior Driven Development) style, a traditional procedural style, or in a data-driven style.
The framework provides the infrastructure for converting those statements to actionable items. Ultimately they get boiled down to a function call -- either from an external library, or one provided by the development team. Those functions typically are written in python, but can be written in Java, a .NET language, or other languages through an interface, depending on how you actually run the test.
Reporting
In addition to being able to run tests, robot framework provides reports and logs that can be used to visualize the state of the product. Logs provide details of every single keyword and function call, reports show the status of complete suites and test cases, and can provide summary information based on arbitrary tags.

Testing methodologies

What is the most commonly used approach used for testing in Java projects (iterative development) ?
My suggestion is that you should have a healthy mix of automated and manual testing.
AUTOMATED TESTING
Unit Testing
Use NUnit to test your classes, functions and interaction between them.
http://www.nunit.org/index.php
Automated Functional Testing
If it's possible you should automate a lot of the functional testing. Some frame works have functional testing built into them. Otherwise you have to use a tool for it. If you are developing web sites/applications you might want to look at Selenium.
http://www.peterkrantz.com/2005/selenium-for-aspnet/
Continuous Integration
Use CI to make sure all your automated tests run every time someone in your team makes a commit to the project.
http://martinfowler.com/articles/continuousIntegration.html
MANUAL TESTING
As much as I love automated testing it is, IMHO, not a substitute for manual testing. The main reason being that an automated can only do what it is told and only verify what it has been informed to view as pass/fail. A human can use it's intelligence to find faults and raise questions that appear while testing something else.
Exploratory Testing
ET is a very low cost and effective way to find defects in a project. It take advantage of the intelligence of a human being and a teaches the testers/developers more about the project than any other testing technique i know of. Doing an ET session aimed at every feature deployed in the test environment is not only an effective way to find problems fast, but also a good way to learn and fun!
http://www.satisfice.com/articles/et-article.pdf
Personal experience would suggest the most popular approach is none at all.
I've worked with TDD (Test Driven Development) before, and my feelings towards it are mixed. Essentially, you write your tests before you write your code, and write your code to satisfy the requirements of the test. TDD forces you to have an extremely clear idea about your requirements prior to starting. An added benefit is that, once you are done development, assuming you followed closely to TDD procedures, you'd have a complete set of test suites to go with the code. The down side is that it takes an extremely long time, and at times, you'd just want to skip a couple of steps (e.g. maybe writing code before tests like a sane person would prefer to do).
More can be read here (wiki link)
Unit testing?
Contract-based programming, a la Eiffel?
Waterfall model?
Different shops do different things. If there were one method to rule them all, you wouldn't be asking this question.
On the premise of doing testing at all, I would say that testing with JUnit is the common approach to do testing in Java.
Although most tests are written with JUnit mostly tests tend to be more integration tests than unit tests. (meaning not testing one thing in isolation but some things together)
Additionally test are mostly not written in a test first approach but in parallel or after a specific feature has been implemented.
If you go to a team that makes more advanced use of testing you might probably find some CI Server (Cruise Control, Hudson) running the tests at least once a day during a nightly build.
In the order of most commonly used approach:
no tests at all
manual tests: running the app,
clicking or providing input, check
results
try to write some JUnits, forget
about them, slide to 2 and 1
Start with TDD, see that it's hard
then slide to 3, 2 and 1
on the theoretical side there are loads of ways to properly test the code.
If you are looking for something practical take a look at
Clean Code Talk. Take a look at the whole series, about 5 talks (can't post more than one link).
My Suggestion for testing of the java project is to keep it simple.
Steps :-
Manual Testing :-Achieve a stable product.
Automation Testing :- Maintain the quality of the product.
Report Generation and reporting :- Let people know the quality of the product.
Continuous Integration :-Make it a complete automated,continuous tool.
When developer will commit the Functionality then Start testing the it module by module.Try to compare the Actual Output with the expected output and against that Log the issues.
When developer resolved with the issues,Start with the Integration Testing and also start testing the resolved state issues and check whether any regression occur due to issue Fixing.
At last when product become the stable one,Then start for automating the the modules.
You can also follow automation step by step like:-
1.Automating the modules.
2.Report generation and send mail for product HealthCheck.
3.Continuous Integration and Automation testing on private server on local machine.

Reducing the pain writing integration and system tests

I would like to make integration tests and system tests for my applications but producing good integration and system tests have often needed so much effort that I have not bothered. The few times I tried, I wrote custom, application-specific test harnesses, which felt like re-inventing the wheel each time. I wonder if this is the wrong approach. Is there a "standard" approach to integration and full system testing?
EDIT: To clarify, it's automated tests, for desktop and web applications. Ideally a complete test suite that exercises the full functionality of the application.
If by "make integration tests and system tests" you mean automated tests, then the answer is no, there is no standard approach. What approach choose will depend on:
the characteristics of the application (e.g. does it have a GUI?, is it read only?, how many external dependencies does it have, etc)
what you are trying to test (maybe you only need GUI tests, or perhaps the opposite is true and you don't really care about the GUI but the internal logic is critical)
how quickly you want to see the results (e.g. the more you stub out the faster your tests become)
the skillsets on your team
Personally, I love any approach that integrates with JUnit. JUnit is a fantastic framework which is well supported and easily tied into a continuous intergration server. Here are a few possible approaches:
Selenium with JUnit - Fantastic tool for driving web applications
Concordion - for all application types. Integrates with JUnit and allows plain english specifications of tests. Your 'fixture'/test code will hook into key words in the specification and assert or perform actions on them.
FEST - for swing applications, again it integrates with JUnit (see a theme yet? ;) (more choices here)
The above examples provide a tremendous amount of out of the box help for testing. Of course, they still require effort to wire to your application and maintain, but the advantages are well worth it. In addition to the above, you may need to be thinking about how to stub or mock out areas of your application. Perhaps you want to do all of your testing "under the GUI" or "above the database". In the first scenario, you'll need your tests to start at the points in your code where the GUI would interact with it and in the latter you'll need to stub out the services which interact with your database.
Point being, there's lots of ways to do this. Best start with a very clear understanding of what you want to get out of your testing. Then learn what existing frameworks are out there to help you based on what you want to test, and finally, don't try to conquer the world in a night. Start small getting a few tests running. Get the green bar (always a joy to see!) Get a stable proven platform for testing and make sure you're happy with it. Then add more as you go along.

Categories

Resources