Running TestCases in JUnit on Ubuntu - java

I am coming from Python world, so please forgive my ignorance. I am trying to learn TDD with JUnit framework in Java. I am following the method described by daniel kullmann in following thread: [How to install Junit][1].
The steps I am following are:
Writing Test Cases
Running command javac -cp /usr/share/java/junit4.jar Test.java
then java -cp /usr/share/java/junit4.jar:. org.junit.runner.JUnitCore Test
So far So good. But my question is:
Do I need to run both full line of command when I have to test my class ? I mean can't it be javac Test.java and java Test ? I have exported the path in .bashrc as below:
export JUNIT_HOME=/usr/share/java
export PATH=$JUNIT_HOME/junit4.jar:org.junit.runner.JUnitCore:${PATH}
I have downloaded latest junit framework 4-11 and kept at location /usr/local/JUNIT. But when I am running command java -cp /usr/local/JUNIT/junit-4.11.jar:. org.junit.runner.JUnitCore Test, its giving the error below:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at org.junit.runner.Request.classes(Request.java:75)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:96)
at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)
at org.junit.runner.JUnitCore.main(JUnitCore.java:40)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLC
Can someone please guide me.
[1]: https://askubuntu.com/questions/64213/how-to-install-use-junit

Related

Error when starting example code in JPVM

I am trying to run the example code provided with the JPVM,the java version of PVM.
I am able to start the JPVM daemon without any errors but when I try to run the example provided I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: jpvm/jpvmException
Caused by: java.lang.ClassNotFoundException: jpvm.jpvmException
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: hello. Program will exit.
I was running the examples from the examples directory, I copied the .class files into the JPVM root directory and ran them from there and it worked.
apparently the jPVM root directory is the working directory and examples need to be ran from there.

I can't import fixture into my fitnesse page

I wanted to begin test my Java Apps with Fitnesse, but I have a big problems right at beginning.
My fitnesse page to test my very simple class is:
!contents -R2 -g -p -f -h
!define TEST_SYSTEM {slim}
!path /home/user/NetBeansProjects/dotestow/build/classes/dotestow/
!|dodawanie|
|l1|l2|add?|
|10|2|12|
|10|35|45|
|60|4|33|
My class is just normal Java class created by NetBeans, here is the code:
package dotestow;
public class Dotestow {
private int l1, l2;
public void setL1(int l1) {this.l1 = l1;}
public void setL2(int l2) {this.l2 = l2;}
public int add()
{
return l1+l2;
}
}
When I click test, it just shows:
Exception in thread "main" java.lang.NoClassDefFoundError: fitnesse/slim/SlimService
Caused by: java.lang.ClassNotFoundException: fitnesse.slim.SlimService
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: fitnesse.slim.SlimService. Program will exit.
What am I doing wrong??
##EDIT
When I run
java Dotestow
in my /Dotestow/build/classes directory, i got output:
Exception in thread "main" java.lang.NoClassDefFoundError: Dotestow (wrong name: dotestow/Dotestow)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Dotestow. Program will exit.
Answer Updated
Looks like FitNesse.jar is missing from the classpath or JRE missmatch with the FitNesse jar version. Please check if Fitnesse.jar is added to classpath in netbeans.
Regards,
Explicitly add fitnesse.jar to your classpath using !path, giving the full absolute path to the .jar
Change this
!path /home/user/NetBeansProjects/dotestow/build/classes/dotestow/
for this
!path /home/user/NetBeansProjects/dotestow/build/classes/
|Import|
|dotestow|
or
remove (from your Class)
package dotestow;
and use javac to complile :D

Java Error, java.lang.NoClassDefFoundError: org/myorg/WordCount in Hadoop

I'm very new to Hadoop. I followed the basic tutorial about how to create word count program in hadoop. Everything was fine. I than tried to create my own map reduce, and put it in a separate jar file. When I tried to run the program, it gives me that error:
shean#ubuntu-PC:~/hadoop/bin$ hadoop jar ../weather.jar weather.Weather /user/hadoop/weather_log_sample.txt /user/hadoop/output
Warning: $HADOOP_HOME is deprecated.
Exception in thread "main" java.lang.NoClassDefFoundError: org/myorg/WordCount
at weather.Weather.main(Weather.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
Caused by: java.lang.ClassNotFoundException: org.myorg.WordCount
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 6 more
But the problem is , it's looking for WordCount class...
If I am not wrong you are missing the jar wordcount.jar.Please add it to build path.
My advice: you put "package" path first removed. This makes it easier not reported NoClassDefFoundError errors. javac compile time: javac-classpath "$ HADOOP_HOME/hadoop-core-1.2.0.jar: $ HADOOP_HOME/lib/commons-cli-1.2.jar"-d. / weather
litianmin#gmail.com

setting the class path on linux to run java program

I am trying to run this command on linux... compilation is successfull but while running it gives error.
Executing this command:
java -cp .:/smash/same/hope/ant-launcher-1.6.1.jar src.vp
output
Setting the value for property-debug
Fusion Repository/asd/file/repo
Logs Directory
Running validations
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Project
at src.vp.call(vp.java:114)
at src.vp.main(vp.java:172)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Project
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
... 2 more
Can some one help me to solve it...
You've included the ant-launcher jar file, but that doesn't contain the whole of ant, I'm sure. Look for the ant jar file that includes the Project class. (I'd expect it to be ant-1.6.1.jar based on the other file you've specified.)

java runs fine with 'absolute' path, doesn't run with CLASSPATH specified

my program is in package pl.edu.uj.tcs.crazySocket; due to some requirements. I work in the crazySocket directory. In order to compile the program I use command
CLASSPATH=~/prog/colosseum/data javac tictactoe.java
and that succeeds. I want to run the program. I change javac to java and get rid of the '.java'. I get
Exception in thread "main" java.lang.NoClassDefFoundError: tictactoe
Caused by: java.lang.ClassNotFoundException: tictactoe
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
when I get up in the tree directory to the ~/prog/colosseum/data and run java pl/edu/uj/tcs/crazySocket/tictactoe all works fine.
What's wrong with the CLASSPATH? Shouldn't it work both with javac and java?
There's nothing wrong with your classpath, it's your call to java that's wrong.
You need to specify the full qualified class name pl.edu.uj.tcs.crazySocket.tictactoe.

Categories

Resources