Arquillian: how to run a test without packaging/deploy/start/stop tomcat - tomcat7

I'm wrinting a junit test with #RunWith(Arquillian.class) annotation like described in https://docs.jboss.org/author/display/ARQ/Drone
While writing the test I would like to rin it without wait package war, start tomcat, deploy war, stop tomcat each time.
I run test inside eclipse and I can run tomcat with my web application once and run test multiple times inside the IDE.
Is there any parameter to let Arquillian use an already deployed and running application, without change the source of my test class?

Nope.
Arquillian is about creating deployable archive and testing it inside true server container.
By the way: if you are looking for ways to speed up your development, then take look at tomcat remote adapter. Generally with remote adapter you don't have server startup for each test launch. Just start it manually once.

Related

Run Spring Boot application with test application.properties

I've just installed Cypress to run e2e tests and that requires my Spring Boot app running so it can plug into the browser to run tests.
I already have an application.properties file under test/resources which creates an H2 memory database populated from a test/resources/data.sql to run my unit and integration tests.
I want to start my app using those test resources so I can run Cypress tests with my testing environment, is that poosible?
I tried changing SPRING_PROFILES_ACTIVE env variable to test but it doesn't take my config files under the test folder, what can I do?
test/resources/application.properties is, as far as I understand it, purely for use in (unit/integration/service) tests that live in test/.
Try creating an additional application-test.properties file in main/resources. This should be used when you have the test Spring profile activated (although it might be better to choose another name for the profile to avoid confusion).

how to run tests from a jar file on a remote machine?

I have a spring boot project where I'm using gradle for dependency management. I copy the project jar to a remote machine. There I want to run the unit tests using my jar file. I'm using junit for running the unit tests. How do I run the unit tests from my jar file in the remote machine?
There is something unclear in your understanding of Jar / unit testing.
Unit tests are made to help building your application in a proper way. You are able to perfomr some tests against your classes. To relate this to a JAR file, your unit tests are here to make sure you build a JAR that "works" (i.e passes your tests).
There is therefor no reason to try executing your tests on the remote machine. Besides, if you open your Jar file (which is just a Zip), you will see that your test classes are not inside. That is because, in a Jar, you only want classes that will be used on production.
Instead, asks you this :
- What are you trying to achieve but running unit tests on the remote machine ?
- Isn't it more like a integration or end to end tests ? Basically, what you want is : deploy the Jar on the server an make sure it still working.
If you really run your tests on your remote machine, then you can go check the link in your comment : How to run JUnit test cases from the command line. I wouldn't recomment, because, like I said, there is a few chances (depends on your configuration of course) that your test classes are embedded on your jar.
Hope it helps you thinking. Don't hesitate to update your posts to add more information.

How To Deploy A Spring Boot Rest Project ByPassing Hikari Test Connectivity?

I am porting my old Eclipse Restful project into Spring Boot 2. So far I am happy that my project is ready to deploy in production, BUT...
When I do "mvn clean install" the process fails since it tries to validate an internal IP address for my production DB server.
Current Condition: I work from home and, I don't need to test the connectivity on my computer, since I have no access to internal network, So I need to do a RDP to deploy the project.
Question: In Eclipse you can deploy any project without forcing to test the connection pool , can I do the same with Spring Boot 2? Can I bypass this initialization from Hiraki?
Thanks in advance for any info.
mvn install by default will run your test cases, and as part of that it will bring up your Spring Boot app to run those tests. Even if we disable the Hikari connect tests, without a proper database connection many other things will likely subsequently fail.
Is there a dev db server at work you can test against? (Or can you set up your tests to run against an in-memory db like HSQLDB?)
If you're very confident that you don't need to re-run the tests, you can disable them during install with:
mvn install -DskipTests

Tomcat crashes after setting environment for Jacoco Agent

I have a simple Spring boot application having some REST API's exposed.
I want to test the coverage for code by calling the these rest endpoints from of my testcases, below are the constraints for me:
The application is running on a remote machine, inside tomcat.
My prefered way is to use Jacoco to generate the coverage report
with maven-surefire or maven-failsafe plugins.
Currently, I'm trying to attach jacoco agent to Tomcat (where my application is deployed).
Below are the variables that I'm setting in setenv file in tomcat:
SET JACOCO= -javaagent:"C:\packages\jars\org.jacoco.agent-0.7.5.201505241946.jar"=destfile="C:\jacoco.exec",append=true,includes=*
SET JAVA_OPTS=%JAVA_OPTS% %JACOCO%
But, when I try to start tomcat with this configuration it crashes without any logs, can anyone suggest any other way to generate the coverage for remotely running application?

Maven/Spring: Automatic Test Run of Generated WAR

Let's say we have a project that consists of some Eclipse-projects and Spring 3.1, the final result is a WAR-file. We use WTP for development. All the unit tests and integration tests are working (our Maven does this automatically). The project runs in WTP with a local configuration. In other words everything looks as if it is ready to roll.
Now we want to test run that WAR-file with different sets of configuration files for different platforms. The test should only start the context and see if that causes any issues (missing/misspelt property in a property file, too many beans for auto-wiring, ...). AFAIK it isn't necessary to have access to (or it accessible to) the outside world. Basically it should only start the context, close it and continue with the next configuration. If one context fails, the build should break.
How should we do this? Can we do this with Maven? Something external?
EDIT: Forgot to say: We will run our stuff with Tomcat 6.
Sounds like you are talking about integration test.
You should look at the failsafe plug for this:
http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html
Using jetty and maven-failsafe-plugin You need to bind one of
jetty:run, jetty:run-exploded or jetty:run-war to the
pre-integration-test phase with deamon set to true, bind
failsafe:integration-test to the integration-test phase, bind
jetty:stop to the post-integration-test phase and finally bind
failsafe:verify to the verify phase. Here is an example:
Another possibility is a selenium test. Selenium tests require the war to be deployed and running before the tests are run. So there are plugins that do all this.
Then you would have a very simple selenium test case that just made a simple http request to the app to see if it was running.
You would use a different profile for each different configuration you wanted to test.

Resources