How to test a web application with jUnit/selenium from Jenkins that is deployed outside maven (in this very Jenkins) - maven

I have to test a webapp, that is build with maven from Jenkins as CI. The Jenkins instance deploys the webapp via script as 'post build step' to a test enviroment. After the deployment some integration tests should be fired and the results should go back to the jenkins instance.
I can't let maven itself deploy the webapp and utilize surefire/failsafe, because I am not allowed to do so.
I already have a little java app, that uses Selenium WebDriver to perform JUnit tests. I could run this app as 'post build step' like this:
java -cp /usr/share/java/junit.jar junit.textui.TestRunner [test class name]
but I have no ideas how to include dependecies (probably somehow like this: Selenium Scripts on the command line) and how to get the results back to Jenkins.

Related

Running API tests in Teamcity build step

I have a Spring Boot Maven app. There is a bunch of API tests using RestAssured, inside the project. These tests are not marked as #SpringBootTest, therefore when running them, the context of the application is not raising so to make tests pass the application must be up and running before.
I'm creating a Teamcity build in which I want to:
Start the app
Run RestAssured tests
Create an artifact
I'm using an Agent with maven installed.
The question is:
How can I create a build step where I run the application on a defined port and then run api tests
against it?
What I've tried is creating such build steps:
Command line: mvn spring-boot:run & sleep 50s mvn test
Maven step/command line: mvn clean package -DskipTests
I thought the spring boot application will start and tests will be ready to start after some time. On successful step 1 I create an artifact.
The problem is that the build step is never exited because of spring boot app running (blocking terminal).

Running selenium unit tests with Spring Boot

I have some integration tests that use Selenium and the HtmlUnitDriver to verify my web app behaves correctly from the browser. In IntelliJ, I'm able to run ./gradlew bootRun to start my embedded web server, and then run my Selenium tests manually.
The tests run as expected.
However, I'm wondering what the best strategy is to run these in an automated fashion on my CI Server (TeamCity in this case). Simply running bootRun doesn't quite work since the task runs until it gets terminated.
Should I create a script that runs bootRun, and then I can terminate gradle somehow after the tests complete? I'd also like to use my application.properties file I have in src/test/resources instead of src/main/resources which bootRun uses normally.

How do I call Junit test (Rest call) cases after deploy war in tomcat through Jenkins?

I am doing continues deployment of my Project war through Maven(Build tool), jenkins(CD tool) and SVN as version control.
I am able deploy war to tomcat , now i want to run some junit which call's Rest web services to that deployed jar, how would jenkins do it ?
You can do this via "execute shell" in jenkins. Firstly, you can check whether "execute shell" is been installed in your jenkins or not it comes as a add-on. If you have shell, you can write a small piece of code to execute your code. Remember this code will be executed on the jenkins slave box which has used to deploy your war.
Start jar file : java -jar .jar
2 ways to do that :
A) mvn exec:exec -Dexec.args="arg1" (this needs maven to be installed on the jenkins box), call you test case directly. Remember before running you should be in directory path.
For example :
cd ${HOME}/(code directory which you want to navigate to in order to run command) - Here HOME is /home/jenkinsUser
Now you are the location(although the first step is optional, you can run without navigating to the location), from where you want to run your unit test case. You can run them as a java command from there, passing the parameter to the deployed jar.

Maven build - run an application then perform JUnit tests

As part of my build process, I would like maven to start a program and then execute JUNIT tests in the same phase, which is the mvn test phase.
I am using Spring Boot as well as the Spring Boot Maven plugin. As you know Spring boot has an embedded tomcat container. So I can just run my application on this tomcat server by just running as an application in eclipse.
For example when I run mvn test, I would like my application to run FIRST and then have the tests executed.
I have seen the exec-maven plugin being used and that you specify the phase in the maven build cycle that you want the application to run. The earliest phase that it allows you to specify is the test phase.
But I'm not sure if the Application will run immediately before the tests?
How do I specify in my POM file that I want the application to run BEFORE the test phase?

How Do I Properly Deploy With An Integration Test Project?

My projects are structured as:
root
common
client
server
test
server and client depend on common. test is a project that contains integration tests and these tests depend on client common and server.
If I add all of these as modules to root, then when I execute mvn deploy on root it will deploy the jars, and then run the integration tests. I only want to hit the deploy phase if my integration tests run successfully.
Is this possible with Maven?
You shouldn't run mvn deploy directly but use the release plugin instead. You have to run
mvn release:prepare release:perform
for doing and deplying a relase. See also this blog post about deploying snapshots.

Resources