Running JUnit tests from Eclipse gives ClassNotFound Error

I try to run tests JUnitfrom Eclipse, but during these tests I get ClassNotFoundException

Full stack trace:

java.lang.NoClassDefFoundError: from Reason: java.lang.ClassNotFoundException: from at java.net.URLClassLoader $ 1.run (URLClassLoader.java:202) in java.security.AccessController.doPrivileged (native method) on java.net.URLClasso .findClass (URLClassLoader.java:190) in java.lang.ClassLoader.loadClass (ClassLoader.java.307) at sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.javahaps01) in java.lang.ClassLoader.loadClass ( ClassLoader.java:248) An exception in the thread "main"

I searched google for this and found that a couple of guys ran into this problem, but none of them seemed to solve my problem. This is probably due to the difference in platforms.

My development platform is as follows

OS: Windows XP
Eclipse JUNO
JUnit4
Maven2

On average, if I run this project using maven, it works absolutely fine.

The weirdest part for me is the name of the class for which ClassNotFoundException is thrown. Class name of.

This is what completely strikes me.

Besides the fact that the stack trace I have ever listed above is all that I get when I get nothing.

I am stuck in this release for 2 days, any help would be greatly appreciated.

+5
source share
8 answers

. , :

  • , Maven
  • Maven Order and Export

, , , , : . , , Maven. IDE. . .

! , , .

+11

Eclipse "Maven → " .

+7

, , - ,

  • , 'src/test/java' 'target/test-classes', , .

  • , , unit test . Go 'Window' → open 'Error Log', .

- - , 'maven' → 'update configuration', .

!

+1

, , " " " ", " " , . . Run configuration tab for project

+1

JUnit eclipse .

0

, . :

, . ( , , )

, , .

0

. .

  • Remove JUnit from the Build Path project and add it again.

  • If set to Create automatically , your workspace will be built again. If you did not configure Build Automatically, then create your own project. Your problem must be resolved.

0
source

You must add the classes you use, for example (spring-boot):

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {DataPoint.class})
public class DataPointTest {

    @Test
    public void TestBuilder() {
        DataPoint.Builder builder = new DataPoint.Builder();

        DataPoint dataPoint = builder.withCount(4).withFirst(1).build();

        assert dataPoint.getCount() == 4 && dataPoint.getFirst() == 1;
    }

}
0
source

All Articles