How to get JUnit version - windows

How to know which version of JUnit do I have installed on my PC?
Second question- How do I upgrade it?

This will print the version of jUnit.
java -cp <path-to-junit-folder>/junit.jar junit.runner.Version

The version that you are running depends on the classpath of the running application. It's possible to have multiple versions on the same machine, but if this is in question you can just write a test for it:
import junit.runner.Version;
class SomeTests {
void testJUnitVersion() {
assertEquals("4.8.2", Version.id());
}
}

To upgrade to a newer version of JUnit, you just have to download the new version and replace the old version with the new jar. It's as simple as that.
There isn't really a nice way to tell which version of JUnit you're currently using, unless you're using maven or something like that. In general, you can tell between
JUnit 3: if you're using the junit.framework.* classes
JUnit 4: if you're using the org.junit.* classes (the tests have #Test annotations on them)
In general, JUnit is backward compatible (JUnit 3 tests can be run under JUnit 4), but JUnit 4 is recommended.

Eclipse shows its runner version on JUnit view when you run your tests

In netbeans in the projects window, expand the test libraries folder of a project that has a test in it. It will say the version in the name of the jar file.

With JUnit 5 you can do something like this:
import java.util.ServiceLoader;
import org.junit.platform.engine.TestEngine;
import java.util.Iterator;
 
final ServiceLoader<TestEngine> loader = ServiceLoader.load(TestEngine.class);
final Iterator<TestEngine> iterator = loader.iterator();
final TestEngine testEngine = iterator.next();
final String version = testEngine.getVersion().get();
Upgrade process depends on your project structure. If it’s a Maven project, you can set the version in your pom.xml. If it’s still unclear I recommend creating another question for your specific build environment.

Related

JUnit class is not displayed in JMeter

I have created a Java project with 1 class containing 2 simple tests, exported as jar and added the jar in my JMeter JUnit folder, now after restarting the JMeter i don't see my class in JMeter even after selecting Annotation 4 option.
This is my class:
package print;
import org.junit.Test;
public class PrintClass {
#Test public void test() {
System.out.println("Hello World..!");
}
}
Consider the following checklist:
Your JUnit test class should have either empty constructor or constructor taking a single string as an argument. Other options are not supported
You should place your .jar file(s) under "lib/junit" folder of your JMeter installation
If there are any dependencies you need to put them somewhere in JMeter classpath as well
JMeter restart will be required to pick the .jars up
In case of any problems first of all check jmeter.log file (normally it lives under "bin" folder of your JMeter installation and contains enough troubleshooting information)
See How to Use JUnit With JMeter article for more details.
Even I faced same kind of issue then I added the dependency jars to the lib file.
Make sure you copy these files at this location -> apache-jmeter-5.1.1\lib
1.Selenium webdriver jar file (selenium-server-standalone)
2. Junit4 Jar file (junit4)
Make sure you add Jar file from eclipse or any IDE to this location -> apache-jmeter-5.1.1\lib\junit
1. Jar file which contains the automation selenium code (Using Junit)
Restart Jmeter and continue which the normal process of adding thread group and adding Junit sampler etc...
This resolved my issue and I was able to run my scripts on Jmeter.
In eclipse make sure that you create a JUnit class, not just the class and add junit annotations to this, even i was facing the same issue, it got resolved when i was created a JUnit class and then uploaded my project in JMeter
Did you put the jar in :
/lib/junit
Check you jar by running below command to see if it is ok:
jar -tvf <your jar>
And its dependencies as described in:
JUnit test classes not showing up in JMeter
See this for more details:
http://jmeter.apache.org/usermanual/junitsampler_tutorial.html

Spring Boot "unable to resolve class" with Groovy

I'm new to Groovy, Spring Boot, and Gradle (using gradle as well) and am trying to build a small test program.
I have a main class EvalMain and a InputObj class in a com.eval package.
#Controller
class EvalMain {
#RequestMapping("/")
#ResponseBody
public static String textTest() {
def iO = new InputObj("dsa", "dasdsa", "U1dBRw==");
return iO.xorString();
}
}
when running "spring run EvalMain.groovy" I get the following error:
startup failed:
file:<filepath>EvalMain.groovy: 14: unable to resolve class InputObj
# line 14, column 18.
def iO = new InputObj("dsa", "dasdsa", "U1dBRw==");
I tried throwing an import at the top but then spring boot complained about this too? What am I missing here? Any help would be much appreciated, thanks!
after adding the import:
import com.eval.InputObj;
I get this error:
file:/<filePath>/EvalMain.groovy: 2: unable to resolve class com.eval.InputObj
# line 2, column 1.
import com.eval.InputObj
^
1 error
Not sure if this is a good way to do it, but I was able to run it with "spring run .groovy .groovy" I wonder if there's the equivalent of a makefile?
Try to run spring run *.groovy.
Spring Boot CLI is for quick prototyping a single Groovy script. It tries to autoload all Spring Boot dependencies, but its your responsibility to include your additional dependencies
If you have just multiple source files you have to pass it to the CLI.
If it is an external dependency, include it with a #Grab, see here.
However, you have Gradle and more than one source file. Therefor it might be the time to switch from the Spring Boot CLI to a normal Gradle project.
Just go to the guides and choose "Build with Gradle". Then you will see an example Gradle build file. Also the Gradle Spring Boot plugin documentation provides samples.
You can start your application with gradlew bootRun.

Serenity BDD ConfigurationException after updating IntelliJ

I try to run my BDD scripts via gradle getting the following error message after updating IntelliJ to 2016.2
No implementation for net.thucydides.core.webdriver.WebdriverManager was bound.
while locating net.thucydides.core.webdriver.WebdriverManager
The code raising the error is this:
#Before
public void jeffCanBrowseTheWeb() {
givenThat(jeff).can(BrowseTheWeb.with(theBrowser));
}
The binaries to the browser are linked like this:
test {
System.setProperty("webdriver.chrome.driver","D:\\lib\\chromedriver.exe")
/* Pass all system properties: */
systemProperties System.getProperties()}
The compile dependencies for selenium-java are pointing to the version '2.53.1'
The gradle command: clean test aggregate
I cannot figure out what is wrong since I did nothing else but updating the IDE. Maybe someone has a hint?
Thanks in advance,
Martin
I ran into the same problem when I was following the example in the article mentioned in your comment. In my case (without using an IDE) it seemed to be a out-of-date dependency (which was renamed).
Try changing the dependency 'net.serenity-bdd:browse-the-web' to 'net.serenity-bdd:serenity-screenplay-webdriver' in build.gradle.

Exception in compiling groovy & java using maven

My groovy file contains:
#Grapes([
#Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7'),
#Grab('org.apache.httpcomponents:httpmime:4.5.1')
])
.......code
I am trying to compile groovy and java code. But I am getting below error:
java.lang.RuntimeException: Transform groovy.grape.GrabAnnotationTransformation#69bda33a cannot be run
This works for me, note that I did change HttpBuilder to v.0.7.1:
#Grapes([
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1'),
#Grab(group='org.apache.httpcomponents', module='httpmime', version='4.5.1')
])
Likely way too late for you to care, but I saw the same error just now.
I suspect the problem is that the #Grab annotation can't take effect because Maven is controlling the dependencies, or perhaps because Maven is trying to compile both Groovy and Java code, and the class loader created by the #Grab annotation can't influence the Java code.
Upshot is, I suspect you (and I) need to move the dependency out of the Groovy class in question, and put it into the pom.xml file Maven is using.

OSGi bundle build issue in Gradle

I have a simple use case of building an OSGi bundle using Gradle build tool. The build is successful if there are java files present in the build path, but it fails otherwise.
I am using 'osgi' plugin inside the gradle script and trying to build without any java files. The build always fails with following error:
Could not copy MANIFEST.MF to
I am sure there must be some way to do it in Gradle but not able to fine. Any idea what can be done to resolve this depending on your experience.
I ran into this today as well, and #Peter's fix didn't work for me (I hadn't applied the java plugin in the first place...). However, after hours of Googling I did find this thread, which helped me find the problem.
Basically, it seems that the error occurs (as Peter stated) when no class files are found in the jar - my guess is because the plugin then cannot scan the classes for package names on which to base all the Import and Export information.
My solution was to add the following to the manifest specification:
classesDir = theSourceSet.output.classesDir
classpath = theSourceSet.runtimeClasspath
In my actual build code, I loop over all source sets to create jar tasks for them, so then it looks like this:
sourceSets.each { ss ->
assemble.dependsOn task("jar${ss.name.capitalize()}", type: Jar, dependsOn: ss.getCompileTaskName('Java')) {
from ss.output
into 'classes'
manifest = osgiManifest {
classesDir = ss.output.classesDir
classpath = ss.runtimeClasspath
// Other properties, like name and symbolicName, also set based on
// the name of the source set
}
baseName = ss.name
}
}
Running with --stacktrace indicates that the osgi plugin doesn't deal correctly with the case where both the osgi and the java plugins are applied, but no Java code is present. Removing the java plugin should solve the problem.
I had the same issue also when java code was present.
Adding these two lines to the osgiManifest closure fixed the problem:
classesDir = sourceSets.main.output.classesDir
classpath = sourceSets.main.runtimeClasspath
-- erik

Resources