Can I run cucumber tests through endpoints as an API? - java

I created a project using cucumber to perform e2e tests of various apis I consume. I would like to know if I can run these tests through endpoints to further automate the application that was created.
That way I would be able to upload this app and would not need to keep calling locally.

You can do that if you create a Rest API with a get method which executes the test runner when called.
How to run cucumber feature file from java code not from JUnit Runner
But I don't recommend you to do that since what you are trying to achieve seems to me similar to a pipeline definition.
If you're in touch with the developers of these APIs, you can speak with them about including your test cases in their pipeline, since they probably have one in place.
If, for some reason, you still want to trigger your tests remotely and set it up by your own, I would recommend you to start reading about Jenkins. You can host it on any machine and run your tests from there, accessing from any machine to your jenkins instance:
https://www.softwaretestinghelp.com/cucumber-jenkins-tutorial/
If your code is hosted in any platform like github or gitlab, they already have its own way of creating pipelines and you can use it to run your tests. Read about Gitlab pipelines or Github actions.

Related

Junit tests with gitlab-ci

So this is my situation:
I am fairly new to gitlab-ci. I don't host my own gitlab instance but rather push everything to gitab itself. I am not using and am not familiar with any build tools like Maven. I usually work and run my programms from an IDE rather than the terminal.
This is my problem:
When I push my Java project I want my pipeline to start the Junit tests I wrote. Whereas I've found various simple commands for other languages than Java to run unit tests I didn't come across anything for Junit. I've just found people using Maven, running the test locally and then pushing the test reports to gitlab. Is it even possible to easily run Junit tests on the gitlab server with the pipeline without build tools like Maven? Do I have to run them locally? Do I have to learn to start them with a Java terminal command? I've beeen searching for days now.
The documentation is clear:
To enable the Unit test reports in merge requests, you need to add artifacts:reports:junit in .gitlab-ci.yml, and specify the path(s) of the generated test reports.
The reports must be .xml files, otherwise GitLab returns an Error 500.
You then have various example in Ruby, Gio, Java (Gradle or Maven), and other languages.
But with GitLab 13.12 (May 2021), this gets better:
Failed test screenshots in test report
GitLab makes it easy for teams to set up end-to-end testing with automation tools like Selenium that capture screenshots of failed tests as artifacts.
This is great until you have to sort through a huge archive of screenshots looking for the specific one you need to debug a failing test.
Eventually, you may give up due to frustration and just re-run the test locally to try and figure out the source of the issue instead of wasting more time.
Now, you can link directly to the captured screenshot from the details screen in the Unit Test report on the pipeline page.
This lets you quickly review the captured screenshot alongside the stack trace to identify what failed as fast as possible.
See Documentation and Issue.

With Eclipse Java: Can I run code/tests from within another JVM?

I know there is remote debugging but I want to go one step further: I would like to run tests in my eclipse that are run within another JVM - i.e. have access to static fields, resources, instances, etc from that JVM.
More specifically: I have an Apache server running locally on my machine and I would like to execute tests as if they were running natively in that very server.
Currently, I implemented my own JUnit test runner that runs within that server/JVM and creates test report XMLs that are written to a folder that I can inspect. But that's a bit bothersome so I would like to be able to run them directly with a mouseclick from eclipse and have them presented there nicely in the JUnit view.
So my question is:
Is there a way to run (not debug) code from eclipse within another JVM?
If so - is this also possible with tests, i.e. run and check the test reports with the JUnit view?
A presume that you are talking about an Apache Tomcat server. (Running unit tests within an arbitrary Apache server doesn't make a lot of sense.)
A Google search didn't yield a lot of leads, but I did come across this:
JUnit-Tomcat: No Mocking Just Testing
Be aware that the source code in the code in the downloadable hasn't been updated since 2006. Apparently doesn't support JUnit 4.0, and it was developed for Tomcat 5.5.
Another option would be to use an embedded Tomcat server within your unit tests; e.g.
https://github.com/mjeanroy/junit-servers
Note: this is not a recommendation.

Can we execute testNG test cases as different services.

I have around 200 testNG test cases can be executed through maven by and suite.xml file. But I want to convert these test cases into web service or any other similar webservice so that anybody can call any test case from there machine and will be able to know whether that particular functionality is working fine at that moment.
But what if no one calls the test webservices for longer time? You won't know the state of your application, if you have any failures/regressions.
Instead, you can use
continuous integration to run the tests automatically on every code push; see Jenkins for a more complete solution; or, more hacky, you can create your own cron job/demon/git hook on a server to run your tests automatically
a maven plugin that displays the results of the last execution of the automated tests; see Surefire for a html report on the state of the last execution of each test

Debug a single JUnit Method in a Play Framework (v2.5) App with Eclipse

We are developing a Java based Play Framework application.
I'm the only eclipse user in my team. My colleagues are using IntelliJ and they are able to run JUnit tests purely from within the IDE.
I wouldn't see this as a problem, since running the tests via ./activator and attaching a remote debugger is no big deal, but:
They can run one single #Test-annotated method of the whole test class and debug it. And I can't even find a way to run a single method using the activator command.
Can anyone point me to a solution?

Selenium Tests with Bamboo

I'm going to execute some Selenium tests after each Bamboo build. As far as I see, the best way is to store them in a separate repo and use specific project (or stage in an existing one) to run these tests. But there is an issue, I can't figure out. I'm using deployment plans to deliver product after build to development environment, so I'd like my tests to be executed, only if the deployment was successful. Does anybody know how to properly express this in Bamboo triggers' terms? Thanks you.
It's rather a confusing and complicated process. As we all know selenium needs a live website to point to in order to execute the tests. There are several ways to accomplish this using Bamboo. I assume you already have the build pipeline set up for automatic deployment. Depending on what you want and how you deploy several agents can be used to execute the tests. Another way is to use Selenium Grid. You want to trigger the selenium task after the deployment happen using several slaves. A grid creates the Hub and Slaves relationship and tells the hub to execute the tests accordingly. Here is some info about the plug-in that can be used to trigger Selenium Testng tests. And, of course, as yo said, you want to create the selenium task to be dependent on the deployment so if the deployment fails then the test will not run. Hope this help!

Categories

Resources