Is it possible to use main method in JUnit? - junit

When I used the main method it return an error message.
Is it possible to run Taurus and converted it to JMX file using the main() method?
or It's compulsory to use JUnit and its annotation in my selenium script when it runs using Taurus tools and then want to convert to jmx.

All supported modules are listed under Selenium Executor page of Taurus user manual.
selenium is a virtual executor, the "real" executors are:
JUnit (Java)
TestNG (Java)
Apiritif (Python)
PyTest (Python)
RSpec (Ruby)
Mocha (JavaScript)
NUnit (C#)
xUnit (C#)
In your case you need to comply with JUnit executor features and limitations, to wit Taurus will only look for methods which are properly annotated which is not the case for main()
If you cannot or don't want to refactor your existing Selenium scripts code you can just set them to use BlazeMeter Proxy Recorder as the proxy for the browser (by the way this is exactly what is Taurus doing under the hood of Proxy2JMX Converter module

Related

2 variants for JUnit execution: TestRunner & JUnitCore

There seem to be two approaches for invoking JUnit tests from the OS command shell:
java junit.textui.TestRunner <class-name>
and
java org.junit.runner.JUnitCore <class-name>
When do we use one versus the other?
Also, are there other ways to invoke Junit tests from the OS command shell?
JUnitCore is an entry point of JUnit - so if you want to run a test programmatically or of from some non-java script, I think, its the way to go for JUnit 4.
TestRunner is something a very old junit 3.x
Notice, that nowadays JUnit 5 is the latest available major release and it has yet another way to run the tests.
The question about different ways of running the tests from command line has been already answered Here so I can't add much to this.
However, I can comment on:
Also, are there other ways to invoke Junit tests from the OS command shell?
Nowadays in regular projects people do not run tests like this, instead they use one of build tools (Maven, Gradle for example) that among other things take care of tests.
So for example if you use maven, you can run mvn test and it will compile everything you need, including source code of tests, will take care about all test dependencies and will run all the tests with the help of build-in surefire plugin.
If you don't want to compile anything (assuming that all the code has been already compiled and all is set, you can use mvn surefire:test)
These build tools are also integrated with CI tools (like Jenkins, etc.) So this is considered to be a solved problem.
So unless you're doing something really different (like writing the IDE UI that should run test selected by user on demand or something) there is no really need to run tests with the options you've mentioned.

How to publish xUnit and jUnit test results to gitlab

I have a jenkins pipeline with test stage that triggered via hook on gitlab. Is there any way to publish test results under gitlab for the triggered build?
Thank you
When looking at a problem like this I typically:
Check the : Jenkins Pipeline Steps Reference - there are gitlab related steps but I don't see anything about JUnit results
Check the Vendor's documentation GitLab's page on JUnit results - it looks like you have to use their runner to get JUnit results - you could investigate whether or not you can run this from your pipeline
Look to see if there is a REST api you can use. The Http Request Plugin is really easy to use to talk to various external servers - if GitLab has an API that you can call you may be able to implement it this way.

Jacoco Sling Junit Integration-Test Execution

One of our test classes extends RemoteBaseTest but Jacoco ignores it completely.
How can I make Jacoco work with Sling Integration Testing?
For Unit Tests everything works as expected.
We are using Adobe CQ 5.6.1.
I see that this issue has been resolved: sling-issue-tracker-2810
but unsure how to implement it - is it even included in the latest CQ-Version yet?
If not how do I manually add it?
I don't know what RemoteBaseTest is but I assume you are running a JUnit "proxy" test which talks to the Sling JUnit server-side tests subsystem and causes the actual tests to run on your CQ server.
If that's correct, the actual test code doesn't run in the client JVM that's running RemoteBaseTest, it runs in the server JVM that's running CQ. So it's on the server JVM that you need to setup Jacoco to collect coverage data.
If you're running some tests on the client JVM (like common JUnit tests) and some on the server JVM via the Sling testing tools, Jacoco has functions to merge coverage data coming from different JVMs. We have this as a work in progress in https://issues.apache.org/jira/browse/SLING-1803 , which is not fully integrated in Sling yet but should be adaptable to any version of CQ.

What is the name of javaw.swing bundle in eclipse plugins folder

I try to run OSGi application as a standalone application but it fails because it can not find the javax.swing bundle.
OSGi is typically used for web-based "thin" clients.
Java Swing is exclusively used for desktop-based "thick" clients.
Q: Is your UI intended to run in a web browser? Are you sure you need Java Swing at all?
If so, please do this:
1) Look at these links:
http://eclipse.dzone.com/articles/dynamic-swing-osgi-demo
How to create Swing OSGi bundles on AWT EventQueue with Spring DM
2) Please post:
a) the exact error message you're getting
b) Your Java version
c) You Eclipse version (if applicable; otherwise give us some information about your build environment)

Hudson + JUnit + embedded GlassFish, how to provide domain configuration?

I'm using NetBeans and GlassFish 3.0.1 to create an EJB3 application. I have written a few Unit Tests, which get run via JUnit and make use of the embedded GlassFish. Whenever I run these tests on my development machine (so from within NetBeans), it's all good.
Now I would like to let Hudson do those tests. At the moment it is failing with lookup failure on a resource (in this case the datasource to a JPA persistance unit):
[junit] SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
[junit] java.lang.RuntimeException: javax.naming.NamingException: Lookup failed for 'mvs_devel' in SerialContext
After searching around and trying to learn about this, I believe it is related to the embedded GlassFish not having been configured with resources. In other words it's missing a domain.xml file. Right?
Two questions:
Why does it work with NetBeans on my dev box? What magic does NetBeans do in the background?
How should I provide the file? Where does the embedded GlassFish on the Hudson-box expect it?
Hudson is using the same Ant build-scripts (created by NetBeans).
I've read this post about instanceRoot and the EmbeddedFileSystemBuilder, but I don't understand enough of that. Is this needed for every TestCase (Emb. GF gets started/stopped for each bean-under-test)? Is this part of EJBContainer.createEJBContainer()? Again, why is it not necessary to do this when running tests on NetBeans?
Update
Following Peter's advice I can confirm: when running ant on a freshly checked out copy of the code, with the same properties as hudson is configured, the tests get executed!
10-1 it is a classpath issue as IDE's tend to swap paths in and out depending if you run normally or unittests.
Try running the tests on a commandline from a freshly checked out version from your SCM. Chances are you'll have the same error. Debugging on your local machine is a lot easier than on a remote machine.
When it builds reliably on the command line (in a separate directory) then it is time to move to hudson.