Can JUnit be used as an alternative to browser testing in Spring? - java

I'm building a Spring web app and up until now all of my testing is using a browser.
This involves starting the server, opening a browser window and checking to see if accessing any of the pages causes an error.
This is starting to get repetitive and doesn't seem to be the most efficient way to do this.
Since the Junit jar file is already in my project, could it be used as an alternative to this browser testing and, if so, any tips on how to get started making JUnit simulate the act of opening a browser to access the web app?

Take a look at Selenium. It allows you to script functional tests using JUnit or TestNG and execute them in a browser, automatically.

You can use the HTMLUnit extension to script to drive the web site from JUnit.
I used a while back and worked fine for thi site I was doing then.
see http://htmlunit.sourceforge.net/

I suggest you to try the Robot Framework. This is an open source testing framework developed by engineers in Nokia Siemens Networks.
It is primarily built on python and the Selenium testing libraries. It also includes support for testing Java/J2EE server side code through Jython libraries. I personally use it in my work sometimes, and writing a test case is just as easy as describing an end-to-end flow through the use of Keywords (most of required ones are already inbuilt). You could go ahead and give this a shot if you find Selenium a li'l tough to work with. The Robot framework provides a fairly simple abstraction over raw selenium, coupled with the power to make Java/J2EE server-side calls too.
Regards,
Nagendra U M

Related

Are complex test scenarios with JMeter possible?

I need to run performance tests on a web application and was wondering if the following can be accomplished with Apache JMeter.
I need to simulate approximately 300 users accessing an application over a set time frame (e.g. 300 users over 10 minutes) and doing some actions, for example:
Logging in
Navigating to different pages
Inputting data
Submitting forms
I'm quite new to JMeter and performance testing in general and was wondering if this is possible? Otherwise are there any better (free) alternatives?
Many thanks.
Of course, it is possible using JMeter.
I would recommend using JMeter/ Blazemeter Chrome extension. BlazeMeter's Chrome extension let you test your application without prior scripting knowledge. It is very easy to create a test with BlazeMeter's Google Chrome extension. Here are some blogs that will help or guide you to use Chrome extension and forth.
There is another option, that is JMeter build in Test Script Recorder. Go through This thread for further detail.
Follow any one of the two procedures to record your scenario and then customize the imported script according to your requirement.
First, record your scenario using Chrome Extension.
Import the generated .jmx file to your Jmeter.
Configure the Test plan according to your requirement.
Actually this is what JMeter is designed for.
For the basics following documentation chapters are very useful:
Building a Web Test Plan
Building an Advanced Web Test Plan
When it comes to the load distribution just use separate Thread Groups to represent different groups of virtual users (like some users are logging in, another are navigating pages, etc.). If you have only one group of virtual users and several actions to simulate you can go for Throughput Controller

What are some alternatives to Selenium?

What are some web UI automation frameworks available out there?
I know about this question, but it was asked 3 years ago and things have changed a lot since then. I just wanted to find out if the answers to that question are still relevant or there have been newer and better tools developed since.
I'm asking this again because after doing some googling I've stumbled upon tools such as Geb and Capybara that were not mentioned as an answer in that question.
there have been newer and better tools developed since.
Take a look at the TestCafe testing framework. It runs functional tests in any modern browser and any device. No WebDriver required.
TestCafe is a pure node.js solution.
It can be easily installed (npm install -g testcafe is enough).
Works without plugins for browsers and additional configuration.
Write tests in ES6 and ES7 JS syntax.
Has smart waiting system, so runs async tests fast without extra waiting.
Can be easily integrated to your CI system.
Support for running tests on remote machines, devices, and cloud.
Free and open source.
You can use WATIR with Cucumber. Infact facebook uses watir for its UI automation.
I would definitely stick with Selenium, TestNG (and Selenium Grid for industrialisation).
If you want something at a slightly lower layer, you can also look at HtmlUnit.
IBM Rational Functional Tester (IE and older firefox builds) or QA Wizard.
RFT runs on Java/Eclipse.
https://stackoverflow.com/a/13024991/423955
Sahi (http://sahi.co.in/) should be the best alternative for selenium. One can use java or javascript for the sahi scripts, php and ruby driver is also available (no personal experience with Ruby or php). Very effective with cross browser as well as cross-platform.
Some of the lovable features are: No explicit wait required. For element identification _near, _under, _in etc ApI's are very useful. Logging/Report, feature is inbuilt with Sahi. No Complex configuration required to run the Sahi scripts

Are there any tools for automatically generating Java code for screen scraping

Is there a way of browsing a web site through a proxy and autogenerating Java code (using HtmlClient) that can play back the requests?
Take a look at Selenium. You can use the Selenium IDE to record a session, and then choose use the "Export" menu item to export it to Java tests. You can then use the Java Client Driver to run the tests.
Not sure what your code generation needs are. Have you looked at Apache JMeter that records test cases through a proxy and also provides interfaces for you to generate your own data.

JUnit - testing a web site

I'm very new to JUnit, but I want to set up some tests which does the following..
Tests a range of server to server API calls - verifying the responses are correct - I can do that fine.
Open a web page, enter data onto it and verify what happens on submit - This I am struggling with. Is it even possible?
I am thinking that I could call a web page using a server side http web request, but I'm not sure how I can interact with the site itself, i.e. enter data into the forms.
Any thoughts?
Thanks
Steve
You could use Selenium for this. I suggest you use the version 2 which is currently in development and should have a beta available soon (alphas are already available).
Have a look at Selenium, it's a system to test web applications (and de facto websites) you can write all your tests in java. There is an ather project named Tellurium, based on Selenium but Tellurium works with groovy and a DSL, it might be easier to handle at first.
How does this works ?
First you create tests in java (Selenium) or groovy (Tellurium)
Then you start your tests. It will work with your web browser. The application will interact with your browser to test every inch of your application (as you coded it)
At the end it give you a report about yours tests, just as JUnit do.
You can also exploit the nature of the web. There's no real reason to render a form, fill it out and submit it to test the form processing code. The display of the form is one HTTP request, and the submission is another. It's perfectly reasonable to test form submission code by mocking up what a browser would send and asserting that it's handled correctly.
You do need to make sure that the form rendering and submission test code are in sync, but you don't necessarily need a full integration for this either.
There are tools that allow testing without booting up a browser... one that springs to mind is HTMLUnit (and there are others). If you find that Selenium is a pain to write, or the tests brittle or flakey, look for simpler tools like this.
I suggest you to try the Robot Framework. This is an open source testing framework developed by engineers in Nokia Siemens Networks.
It is primarily built on python and the Selenium testing libraries. It also includes support for testing Java/J2EE server side code through Jython libraries. I personally use it in my work sometimes, and writing a test case is just as easy as describing an end-to-end flow through the use of Keywords (most of required ones are already inbuilt). You could go ahead and give this a shot if you find Selenium a li'l tough to work with. The Robot framework provides a fairly simple abstraction over raw selenium, coupled with the power to make Java/J2EE server-side calls too.
Regards,
Nagendra U M

is there an option for testing java applications from the outside like we do with the web applications?

I would like some suggestions if your project has some java application elements as well as web then is there an option for testing java applications from the outside like we do with the web applications
Your question is not very clear to me. But from what I understand, I feel jMeter could be something that might help.
jMeter can not only test web applications (from outside) but ALSO standalone java applications.
Also, do not dismiss jMeter as a performance testing tool. There are ample features in it that makes it a good enough tool for Functional testing as well.
Do you mean testing desktop applications through the GUI? If so, there are many tools for doing this, both commercial and open source. Some open-source projects to google for:
Window Licker (I am an author of this one)
FEST
Marathon
Abbot
This is called Blackbox testing.
Typically you would write another program that provides inputs to your applications and verifies the output. This is easier for a command line application but for GUI testing you would need to use a framework like others have mentioned.
Another approach is to write a drive that includes the jar files and directly call the public functions and do input/output testing.

Categories

Resources