Writing Fit/Fitnesse tests using Java - java

I am really new to Fit/Fitnesse and, in general, to test automation.
I am trying to use them from Eclipse.
I have several question about it:
is there a way to obtain the html tables that Fitnesse pass to Fit?
once I write several tests with Fitnesse, is there a way to call them several times from Java without clicking on the Test button of the wiki?
About passing objects from one table to another in a flow. I read about symbols but it seems that, in java, they works only with ColumnFixturewhile I would like to use DoFixture. how to do this?
Finally,is if there is any plugin for eclipse you suggest to use with Fit/Fitnesse?

Regarding you question 2: I would recommend using the JUnit integration (#RunWith(FitNesseRunner.class) to run the test page (or a suite) as a unit test from Eclipse. This also gives you the ability to debug inside your fixture code.
It takes a bit of configuration to get it running 'just right'. In my pre-packaged FitNesse I provide a unit test FixtureDebug where you only have to enter the test name (and you can also use that to run your tests on a build/continuous integration server).

Related

JMeter to execute JUnit tests based on Cucumber (java)

I am a beginner at automation testing.
I am trying to execute tests that were written in java using Selenium WebDriver, Cucumber with Gherkin annotations in JMeter.
When I run my tests without JMeter, I just use the opportunity to run them as Junit test using the runner class (in Eclipse).
To run my tests in JMeter, I created a jar file, uploaded it to Junit sub-folder, all dependencies-jars were uploaded to lib sub-folder.
I tried to create a JUnit request in JMeter, but it didn't help as when we use Cucumber, we don't mark methods with #Test. I have just an empty constructor for my Runner class (as you can see from the picture above).
I tried to add my jar to Test Plan and create an instance of my class in BeanShell, but it is not executed as JUnit tests.
My question is how to run java test scripts that were written based on Cucumber with Gherkin (based on Selenium WebDriver)?
Maybe I have to use other Samplers...
Any examples are greatly appreciated.
I believe you need to run another class, in particular io.cucumber.core.cli.Main, something like:
io.cucumber.core.cli.Main.main(new String[]{
"--glue",
"the package which contains the glue classes",
"/your/feature/file"});
Check out Running Cucumber -> From the command line for all the available arguments explained. By the way, you can use OS Process Sampler for this, it will be way easier.
Depending on what you're trying to achieve it might be faster and easier to convert your Selenium tests into "native" JMeter ones as if you're going to use your Selenium tests for creating the load it will require immense hardware resources and you won't get performance metrics on the HTTP protocol level.

Implementing data driven framework using selenium webdriver

I need to build a datadriven framework using selenium webdriver with java binding. i am bit confused with regards to choosing the right tool for building framework
Could somebody please recommend which framework (i.e. Junit, TestNG, Cucumber) works better with large set of test data
Also, please suggest which data file format i.e. .xls or .tsv to use for executing automated tests from Jenkins(deployed on Linux box)
As fare as I know and what I have earlier used Selenium for is to implement automated test scenarios of a web-application. Would typically be accept-test og end-to-end test (e2e).
These kind of test are what you call Black-Box testing. You give a input and expect a output, but does not know what is going on inside the black-box (you application).
To implement and execute your tests scenarios you would use a test-framework as you also mentioned (JUnit, TestNG, Cucumber etc.).
All test are able to be executed on a build server running Jenkins whether it is unit/integration or e2e-test (which could be implemented with Selenium).
Selenium test are expensive to maintain and often you would run into timing issues which causes test to fail even though the code does not contain any errors.
Therefore it is important to implement the test correct, otherwise you would run into a maintenance hell.
I am not sure if you are new to testing?? Maybe you could benefit from reading a bit about software testing.
The following is a good link: https://www.softwaretestingmaterial.com/software-testing/
Let me know, if I have misunderstood you question totally :)

Creating a Java reporting project -- would like to use JUnit and Ant but not sure how

I'm interested in generating reports for a certain group of (non-software) engineers in my company using JUnit. Unlike typical JUnit testing where you are ensuring objects, methods, etc are bug free, I want to use JUnit to confirm if results in large log files are within range and give reports on it.
My background: Experienced with Java. I am familiar with JUnit 4, I have spent the last hour or 2 looking through ANT documentation and I think I have a strong idea how it works (I just don't know all the XML commands), and I use Eclipse religiously. Specifically Eclipse June (latest).
My goal is to create a slew of testcases that assert if the values in the logs are within the right range. The test class can then be run over and over on every single log file. After each run, the results will be added to an HTML file.
I am aware of the JUnit Report features in Ant but I am having a lot of trouble putting all the pieces of the puzzle together properly. I know I can hack my way through this project quite easily, but I want to do this the right way.
Can any point me in the right direction in how to:
Make the right build.xml files
Set up JUnit classes/suites/runners so that it runs over and over for a given list of logs
Set up ANT so it does output HTML/XML and how to point it to the right style-sheet so it can be opened in IE/Firefox
How to make the output file
Override features so the reports are custom.
What to override for post-processing. (So I can convert the output HTML into a PDF, etc)
How to create a standalone executable that will do all this automatically - Perhaps incorporating a little Swing if the user doesn't supply an input manually.
How to properly loop through many tests (currently I am just making a main function and doing:
code:
public static void main(String[] args) {
JUnitCore junit = new JUnitCore();
RunListener listener = new RunListener();
junit.addListener(listener);
Result result = junit.run(GearAndBrakeFaultLogReports.class);
for (Failure f : result.getFailures()) {
System.out.println(f.toString());
System.out.println(f.getDescription());
System.out.println(f.getTestHeader());
System.out.println(f.getException());
System.out.println(f.getMessage());
}
System.out.println("Done.");
}
I have a feeling that is the "hacky" way of doing it and if I knew how to plug into Ant properly, it will run my tests, generate the XML/HTML and I would have the output desired.
I imagine I will have more questions as this project develops, but I think getting over the initial hump will be very good for me! I know there are a lot of questions, so any help and I'll gladly point bump :) My hope is, someone familiar with these tools can answer all these with a matter of pointing me to web sites, functions, or an example project that does a similar thing.
For creating a PDF from JUnit test results:
http://junitpdfreport.sourceforge.net/managedcontent/
As a unit testing frameword, JUnit reports are very specific to software engineering. Although, you might be able to customize it for a non-unit testing scenario, it will take a lot of customizing. Unlike other testing frameworks (such as TestNG) JUnit doesn't provide the ability to make your own report generator. TestNG, however, can be used to run JUnit tests and even produces a JUnit report in addition to its own reports. TestNG can run your JUnit tests and then create custom reports by providing a custom implementation of the org.testng.IReporter interface.
http://testng.org/doc/documentation-main.html
Having written reports in Java for many years now, I would strongly recommend trying out a reporting tool such as JasperReports and the iReport tool. Jasper Reports can process custom data sources such as your log files and produce reports in many formats, including XML, HTML, and PDF.
http://community.jaspersoft.com/project/ireport-designer

How to unit test legacy J2EE application

This may sound like a vague question but I am looking for some specif pointers.
Our J2EE app is built on Struts2 + Plain Servlets + JSP + iBatis + Oracle
I would prefer to write unit tests in Scala so that I can learn the language on the side as well
What would I need to be able to verify that a spcific column is displayed in the JSP following some specific steps
Click on a link. select some parameters and submit the page to the servlet
Verify that the next page has a specific column inside its <table> tag.
What would I need to create mock requests for the serlvet?
I am trying to write tests like above in addition to core business functionality tests however, the problem is that I am trying to wrap legacy code in unit tests and the code of course is not designed for unit testing.
I wouldn't call this unit testing. As you are trying to test integration of several units. Also it's rather hard to create a unit test for a JSP becuase it has many context dependencies available only when you are in the container.
Instead I would advice writing some automated functional tests that are executed against running (deployed) application.
Frameworks like Selenium may be of great help here as they allow to simulate real user behaviour and make asserts against produced HTML code.
EDIT: Another approach here may be to:
start an embedded servlet container like Jetty within your test code
deploy all your plain servlets and JSPs to that
replace Oracle database with in-memory database like HSQL or Derby
populate it with some test data using DBUnit
and then again use either Selenium (which has Java binding) or HttpUnit to make requests and asserts against generated HTML code.
But again it will not be a unit test, but rather an integration test.
Like everyone said, your not really talking about unit testing. You're talking about functional testing. I'd think hard about what your real goals are. What is driving this push for automated testing? Does the application have configuration issues(i.e. its hard to configure so some parts work and others don't). This might justify building a smoke test suite in selenium targeting your pain pages and test cases. This will also help detect regression bugs.
As for the legacy concerns. No application is beyond help. If you are running front end tests in selenium then it doesn't matter how the code is written as long as its parseable HTML.
As for your actual server side code. You just gotta roll Andy Dufresne style. As you fix bugs and add functionality code with Test Driven Development principles in mind. Rework code that relates to your changes and add unit tests. You'd be surprised at how fast a legacy app can come around if you keep chipping away at it.

Selenium Unit Test using JUnit (Java)

I just want to quickly ask, I found all over the internet and even here on SO, how Selenium IDE can create Java source files from what you are doing in browser. But all these sources result in some Unit Test. For Java I believe JUnit and some other are supported by Selenium IDE.
But I want to ask, why? I mean, if you still need to compile them before executing, why are Unit Tests used instead of just running the code and look if WebDriver throwns any exception? What is the advantage of using for example JUnit here? I know its mostly used this way, I just donĀ“t know why. Thanks.
Here's a couple of reasons off the top of my head:
1) You can hook your selenium tests into your build process (and hence your CI process).
2) You can use JUnit assertions.
3) You can build up multiple suites of JUnit tests (which can then be run in parallel).
I'm sure there's more but I guess it depends on the number of tests you have and the size of the project you are working on. If you're project already has a set of JUnit tests then it's quite nice to be able to write selenium tests without too much effort.
If you use Junit you can quickly recover from failures before starting a new test with the #before and #after annotations. You can also TearDown the tests with it. This also makes the tests more organized.
Not always you get an exception. Your application can handle an exception/user input/ etc. and navigate to different page then expected without throwing an exception - that can be easily verified by JUnit - assert expepected title of a page / presence of an element with actual values.

Categories