Generate JUnit report for individual Test case in Java - java

I am making an framework that internally uses REST Assured. This framework will have the 4 #Test methods for CRUD operations. These methods are called individually by the user. I want the method should generate the JUnit report for each test case which the user calls(GET/PUT/PUT/DELETE).
I tried using surefire-report plugin. As I have read, that will generate report only when we build the project(running all the Test suite)(please correct if I am wrong).
I want particularly my framework should generate the JUnit style report(for jenkins integration) at the end of each call. I used the ExtentReport, but thats not what I wanted actually.
Please suggest any way to get the work done.

Related

Should we write automation test code if we merely write wrapper code?

Normally, when I implement new features, I write corresponding automation test code. But right now we are working on a special project. I don't know if it is good practice to write automation test code.
The project is a legacy project, which doesn't have automation test code. The functions are stable they been there for years. We do not add any new functions to it, and we probably won't in future. We need to change the UI from flex to html, so we need to change the way how we expose APIs. We used to expose API through spring remote. Now we switch to RESTFUL APIs. In other words, we only write wrapper code. We don't write if...else.. or loops. Is it a good practice to write automation test code for the mid-tier in such case?
Yes.
A unit test could verify the parameters passed to the API were correctly passed on to the wrapped component. In this case the wrapped component might be mocked.
An integration test could verify the API (facade) correctly wired the real components, and assert the expected result.

Should we mock in cucumber testing while testing java code. Till what extent we should use cucumber?

I am a Java developer. We want to use cucumber testing in our project. We are working mainly on creating APIs. I am good with unit testing and researching about cucumber.
I am thinking about testing persistence methods - CRUD operations as an starter. My questions is that what could be the scenerios in this testing.
Also should I mock the database by creating tables in the feature file. Should I use mockito with Cucumber to mock call to some other services which connects to database and server.
What should be the cucumber testing in these scenerios and whats the best way to create framework to use cucumber in our Java API's project.
Also, how to populate models if not using database
IMO Gherkin (the language you write Cucumber features in), is good for writing business readable, simple scenarios.
To answer quickly, I would say that Cucumber is not a good fit for testing methods, if it is what you want to do.
As you can see with the file naming convention, you write *.feature files, and I think these files must only contains feature-related descriptions.
However, if you do have features to test, you have to choose how to test them
disconnected, can be run quicky by your CI
you will have to mock everything that cannot start-up in the build lifecycle
and they are solutions to start almost anything using Docker, like Testcontainers
connected to a environment
you do not have to mock anything
your tests may be slower
your tests may break because of the environement (failed deployement, server down, etc.)

Whether Cucumber JUnit can be used to UnitTest Spring?

Whether Cucumber JUnit along with Mockito can be used to test Spring? Wherever I see it's either only using Mockito JUnit or SpringJUnit Runner and have never seen UnitTestCases with Cucumber JUnit+Mockito for Spring..
Whether that is really possible?
The problems those technologies aim to solve is very different.
In an unit test you are trying to test the smallest possible piece of your software (normally a single class) and you abstract (mock) everything else. This is a very good use case for Mockito.
JUnit runner and SpringTestRunner are the engines running your tests, they will take care of configuration and class loading for you.
Cucumber allows you to write tests in a language that is more business friendly (Gherkin) and your goal here is to cover business user cases and test your entire application to see if it solves your problems.
For example: lets say you have an application that gives you the tax value to be added to a check.
You can have a class that given a product connects to an external service and returns the tax rate for that item. To test that class you don't hit the real service, you use Mockito to create a mock service where you can control the returned values. Here you are testing the ability of your class to make requests to external services.
Now you can have a business requirement that says that if you have multiple items in your check only some of them are taxed. Here you write a cucumber test and send the request to your application. Here you are testing the full logic of your app, recognizing items, getting taxes for the right ones and so on.
Thats a case where you will have cucumber and Mockito running on the same app. And who is running them? Most likely the JUnit runner.

Writing Fit/Fitnesse tests using 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).

Convert JUnits to RESTful service

I want to run my JUnits on demand via RESTful api. These are primarily the functional JUnits which test the RESTful endpoints, so they don't directly test source code.
Is there any tooling available to scan existing JUnits and provide those a list of available tests along with the ability to execute those tests.
I am thinking of something which similar to the following REST calls --
GET unit-test-service/tests (to get the list of tests)
GET unit-test-service/tests/123456?execute=true (to execute the test and return test result as response.)
Any pointers are greatly appreciated
Try using Fitnesse it is a simple wiki based testing tool having test classes in Java or other languages. It also has the REST urls where you can retrieve test cases as xml and parse it or run it as well.

Categories