Run integration test suite with maven - junit

I'm trying to find a way to run a single integration test suit with maven.
I have a suite defined like that:
#RunWith(Suite.class)
#Suite.SuiteClasses({
ITest1.class,
ITest2.class,
})
public class TestSuitIT {}
I try to tun it with the command
mvn -Dskip.unit.tests -Dit.test=TestSuitIT integration-test
But it doesn't run the suit. I also tried with the full package.
It does work if I run a single test, but not with the suite. Is it even supported?

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.

yii2 install, configure and run codeception tests

I'm writing this because yii2 official documentation is still not complete and codeception documentation itself refer to yii2 official docs..:).
I have some questions:
In my yii2 app root there is a directory "tests/codeception", this means that codeception is already installed in my project?
in vendor/yiisoft there is another codeception directory "yii2-codeception" what is it?
the documentation say to create a yii2_basic_tests database and to run a migration, but migration script create only a "migration" table, is it correct?
the integration with yii2 provide some web interface or I must run the tests from console scripts?
Someone can explain me how to install and configure codeception in yii2 basic app step by step?
Thank you
Alessandro
I am doing some like that:
composer global require "codeception/codeception=2.0.*" "codeception/specify=*" "codeception/verify=*"
And next:
ln -s ~/.composer/vendor/bin/codecept /usr/local/bin/codecept
Then I am available to do globally
codecept run
First make sure you read this a couple of times http://www.yiiframework.com/doc-2.0/guide-test-environment-setup.html
Afterwards the actual tests are easy to set up. Make sure you make the codecept command work like it says on the last line of the link above. After you install an Yii app you have to go to the tests folder and run
codecept build
to initialise the tests. Then run
codecept run
to run the actual tests.
You can run
codecept run --coverage-html
to get the code coverage for your project.
I have never got the acceptance testing working with code coverage but I got acceptance working without coverage and unit&functional with coverage.

Junit reports for Hudson

I am able to successfully run my JUnit test suite from the command line and now I want run these tests from Hudson.
However , for Hudson to generate the reports , it needs a results file (I think in xml format) .
How do I generate a results file from JUnit ?
I am using the following command to run the tests :
java com.nvidia.tests.TestSuite1
Thanks in advance .
Parag.
If you're using ant, you can look at the JUnit task for ant. This is probably the easiest way. You can just add the task at the appropriate place in the script.
If you're using maven, look at the surefire plugin for maven which will automatically run the tests and create the reports in jenkins.
EDIT: If you're not using any build tool (which you should be), then just add the ant build script to jenkins, and you should get the reports automatically.

Hudson + Maven + Emma/Sonar = Build Cycle Runs 2x

I have a bunch of Maven projects building in Hudson with Sonar sitting in the side-lines. Sonar gives me Sonar stats, FindBugs stats, and code-coverage.
I've noticed that regardless of if I use Sonar or if I use EMMA via Maven directly, the entire build cycle runs twice. This includes init (which in my case, reinitializes the database -- expensive) and unit tests (a few hundred -- also expensive).
How can I prevent this? I did a lot of reading, and it seems like this is due to the design of code-coverage plugins -- to keep uninstrumented classes separated from instrumented ones.
I've tried configurations like:
Maven runs: deploy, EMMA
Maven runs: deploy; deploy to Sonar on completion
The sonar documentation recommends running the sonar plugin in 2 stages:-
mvn clean install -Dtest=false -DfailIfNoTests=false
mvn sonar:sonar
The tests are bypassed in the first phase and run implicitly in the second stage.
A one line alternative is to run the following command:-
mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true
but this will run the tests twice - as you have found.
To add to #Strawberry's answer, you could reuse the unit test reports instead of running them again. Refer to the section Reuse existing unit test reports in the sonar documentation
Once this is done, you can configure the following in Hudson
clean deploy sonar:sonar

Selecting specific tests to run in gradle

I'm trying to fix our messy failing test runs, and, unfortunately, I'm very new to gradle. We currently have testng, junit, and I'd like to add some spock tests to the mix as well. I'm not quite sure how gradle determines which tests to run when I type "gradle test". How can I prevent the testng &/or junit tests from running? How can I get gradle to start running my spock tests?
By default, the test task runs all JUnit tests it can find, which includes any Spock tests. To make it run TestNG tests instead, configure the task as follows:
test {
useTestNG()
}
If you have both JUnit and TestNG tests, you need two test tasks, one for each test framework.
To run a subset of tests, use the -Dtest.single system property. For more information, see the corresponding section in the Gradle User Guide.
You may provide using the command line:
$> gradle test --tests org.somewhere.MyTestClass
Or even
$> gradle test --tests org.somewhere.MyTestClass.my_test_case
$> gradle test -Dtest.single=YourTestClass