Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run JUnit tests automatically in Jenkins without maven or ant

I am currently setting up a continuous integration tool with Jenkins. I would like to run JUnit tests everytime a build is made. My problem is that none of the projects that will be tested use maven or ant. So I would like to know if it is possible to run these tests without maven or ant, and if it is, how do I do it ?

Thank you in advance for your answers

like image 399
Bosion Avatar asked May 21 '13 12:05

Bosion


People also ask

How do I run JUnit tests automatically?

Running Single Test Class. To run JUnit 5 tests from Java code, we'll set up an instance of LauncherDiscoveryRequest. It uses a builder class where we must set package selectors and testing class name filters, to get all test classes that we want to run.

Can JUnit be run automatically?

JUnit provides Test runners for running tests. JUnit tests can be run automatically and they check their own results and provide immediate feedback.

Can I use Jenkins without maven?

Sonar runner is usually executed as a maven plugin but Jenkins can invoke it without the need of maven through the Execute SonarQube Scanner task. Navigate to Manage Jenkins -> Manage Plugins` and ensure that the latest version of SonarQube plugin is installed.


1 Answers

Have you tried ClasspathSuite by Johannes Link?

From the documentation:

The mechanism is simple. Just create a new project in Eclipse and add all projects that contain tests you want to run to its build path. Now create a class like that:

import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
public class MySuite {}

This will execute all JUnit4 testclasses (those containing methods with the @Test annotation) in the projects classpath.

You can then run it using JUnitCore.

java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore [test class name]

For more information, see How to run Junit testcases from command line?.

like image 155
Matthew Farwell Avatar answered Sep 28 '22 08:09

Matthew Farwell