Exclude step from gradle build for specific test classes - docker

I'm new to gradle, and I'm sure that this can be done somehow, but I can't figure out how - project does use dockerCompose task. It's spinning some docker dependencies up for tests. The problem is, it done in very dummy way:
dockerCompose.isRequiredBy( test )
which means that every single time I run tests from IDE, even if I'm running single unit test, that does not need docker dependencies at all, it's still starting up some docker containers(or failing miserably if docker agent is down).
I would like to run dockerCompose step only for some tests, only the ones that really need it. I don't have full conception, how I would like to mark those tests, but probably the easiest and most readable solution would be to use name, let's say ***DockerTest or ***IntegrationTest. And only for those ones I would run dockerCompose step.
I tried few different approaches, f.e. using system property in test's Before method and if statement in build.gradle(but it's already too late, dockerCompose already started before we went to test step), I've tried registering new task that extends Test and then to use 'filter' command, but it does not seem to work either(the task is started regardless from the test name, so it does not help me at all).
What would be the best way to do it, if that's even possible?

Related

Play framework services integration testing in Jenkins CI

I want to use Jenkins CI for integration testing with Play framework. My scenario is as following:
I have 2 projects, Project A and B.
Project A depends on Project B. The dependency is as such that to run tests on Project A, I need to start Project B first.
I already have unit tests in Project A but I need to test the integration of Project A and B.
I am using SBT plugin to execute the SBT and the Project A and Project B are working fine separately.
I could not figure out a proper way to do it. The issue I am facing is that I need to run Project B as a pre-build step but the Project B must be kept in running state but Project B is ended as soon as the build step executes run action of sbt and finishes the build which I don't want.
The command I execute to run Project B is clean compile run which executes as an action to SBT launcher.
I tried SBT stage and then run the jar but that is also causing the issue that the jar halts the control of the build and Project A doesn't get a chance to start.
I also checked Spawning a process in Jenkins but I couldn't make it work too. I am using Ubuntu and I tried using nohup instead of daemonize as described in the link by adding it as Execute shell script build step and it starts the Project B server process and kills it after some time. I also don't think that it might be the only way to do what I want to do.
May be I am using Jenkins wrong or may be I need to look in another direction so any help on this is much appreciated.
I ran into a similar problem where I needed to free the console for running other stuff. I did something similar (i.e. creating a script with the sbt commands), then running the script with a nohup like so:
nohup ./myScript.sh &
and the Play! app runs just fine in the background.
Remember to use different ports in your case, since you're running two Play! apps.

Can yeoman tests be run in parallel?

We just hit an issue with yeoman-generator tests when they would pass when run in isolation but fail when run in parallel with other tests.
Specifically, we call require('yeoman-generator').test.run() to run the generator and then use require('yeoman-generator').assert.file to check that the correct files were generated, which is what the documentation says. However, the assert would sometimes fail saying the files don't exist.
How does the interaction between test.run() and assert.file work? Where are the files written? Is is a global variable / temp file that is always the same and therefore can be overwritten by other tests running at the same time?
This is the test, and an example of a failing build.
There's a github issue with detailed discussion and here's a discussion on how the tests suddenly started passing when run in isolation.
We are using the Jest testing framework which runs tests in parallel.
Looks like Yeoman tests can't be run in parallel.
require('yeoman-generator').test.run() does create a temp directory but then changes the current working directory to that directory. This interferes with other tests that also rely on the CWD and therefore the Yeoman tests can't be run in parallel with other tests.
Relevant comment in run-context.js and process.chdir in helpers.js.

How to organize tests sequence in ant or jenkins

I use selenium WebDriver with junit, ant and jenkins.
I set up jenkins to use ant build.xml to run my tests. But currently I run only one tests. In build.xml I set variable which is used in each test. So to run test in Jenkins I set in Targets:
build MyTest1 -Dvariable="value"
I want to run all tests in sequence one after another. I try this:
build MyTest1 -Dvariable="value" MyTest2 -Dvariable="value"
But 2 tests began run in browser at the same time. How can I organize needed sequence. Maybe there are some ways to do it in build.xml? I guess I can create target, in which call targets which runs tests, but how set my variable in that case? I'm new to ant so please advice me solution.
I need to clarify - my tests are independent, I won't run them in some stable sequence. The problem is that tests are running in parallel in browser. I need to run first test and only after it finish - run second test.
First of all, tests should have little dependencies. In your case, your tests depend on a global variable - try to get rid of it. Use a "configuration" object that you can modify from tests in a safe way and which your application code then uses to configure itself.
Which reduces the problem above to "how do I collect a number of tests" to which the answer is: Use a test suite:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
#RunWith(Suite.class)
#Suite.SuiteClasses({
MyTest1.class,
MyTest2.class
})
public class JunitTestSuite {
}

How to setup Bamboo to work with codeception?

I have been trying to get Bamboo working with codeception tests. I am using codeception to test my code in a symfony project.
After some research I found an article on how to setup Jenkins with codeception.
Once read I figured out that I should use Ant to run the codeception commands that run the tests.
The problem is I don't really know where to put everything. This article explains all the fields for a new Ant task but nothing seem to work.
Can someone please help me?
In case anyone else comes across this, this is how I have gotten codeception working in bamboo.
In Admin > Server Capabilities. Add a new executable for Codeception with the path /usr/local/bin/codecept.
In your job, create a new task of type Command. Set the executable as Codeception. The arguments should be run --xml (and any others you need).
Next, create another task with the type of JUnit Parser. Set the custom results directory to tests/_log/*.xml.
This works perfectly for me.
Additional: If you do not have admin rights to the server, set the command executable as PHP and add ./vendor/bin/codecept run --xml as the arguments.

How would you run jasmine tests on a CI environment *without nodejs*

I have a bunch of jasmine tests that I would like to run on a jenkins CI server.
At the moment, we use an html page that runs the specs, that a developper can open in a browser on its own machine.
The transition to CI would be easy if I had access to some kind of server side test runner (like karma), however for some undisclosable reasons, I can not run nodejs on our CI server.
So in the spirit of creativity-under-constraints, what could I use to automate jasmine tests without node ? (But anything that can run with maven and a jdk is probably fine...)
You can make your test automatically spawn a browser with the page that runs your unit test. The tricky part tough is to get the result back to the main test runner. The solution that I have found for that is to use a custom jasmine reporter (you just need to implement the same function has to other reporter) and when a spec has finished to run you do an AJAX call to write that result in a file. The main runner just needs to wait until something is written in that file to see the results. Once the test are finish, just don't forget to kill the browser, otherwise your CI server will be flooded by window.

Resources