I am writing JUnit Test case using powermock i.e. #RunWith(PowerMockRunner.class) and using #PrepareTest annotations and added all the Power mock dependencies but still why I am getting java.lang.NoClassDefFoundError: org.powermock/tests/utils/RunnerTestSuitChunker.
Any Suggestion will be appreciated.
Related
Currently I am trying to upgrade my Jakarta EE sample project to Jakarta EE 10, and the testing libs is upgrade to Arquillian 1.7.0.x and JUnit 5.
But there is an issue of method injection which works well with Arquillian 1.6.0/JUnit 4, but failed in the new stack.
The problem is JUnit 5 try to resolve the method parameter with its own ParameterResolver, what I need here the method parameter is injected by Arquillian like a CDI Injection.
There is a Method parameter injection discussion in the Arquillian Github issues.
The following is an Arquillian test example to inject an initial Page instance.
#Test
public void testHomePageObject(#InitialPage HomePage home) {
home.assertTodoTasksSize(2);
}
When running the tests, it will fail due to lack of related JUnit 5 Parameter resolver.
I also encountered similar issues when integrating Vertx and Weld/CDI, see https://github.com/hantsy/vertx-sandbox/tree/master/post-service-cdi
Is there an option to skip parameter resolving by JUnit 5?
I am Using Junit5 with Quarkus F/w.
when I try to Mock Service class by Using #InjectMock(io.quarkus.test.junit.mockito.InjectMock) it gives an error
Like org.junit.jupiter.api.extension.TestInstantiationException: Failed to create test instance
and another side when I am using #InjectMocks which belongs to (org.mockito.InjectMocks) package
Junit Running fine but, the Service class Did not Mock it is hit a real DAO class and inserted data
inside database
total conclusion in #InjectMocks is not working.
Please give me any suggestion but this mocking
Thank you.
I am facing one problem while running the Junit scripts. I am getting the below error message.
I have three java classes under which i have commented all the #Test annotations from Class A and Class B but have four #Test annotations in Class C..but still it is showing the below error message.
Can anyone help me how to fix this issue?
Error: java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:169)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:104)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:355)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.Parameterized$TestClassRunnerForParameters.<init>(Parameterized.java:171)
at org.junit.runners.Parameterized.createRunnersForParameters(Parameterized.java:319)
at org.junit.runners.Parameterized.<init>(Parameterized.java:282)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Can anyone please help here?
Ensure that all of your relevant test case objects are public and non-abstract, and that your test methods are annotated with #Test but are also public void and non-static.
See more at the JUnit Getting Started Guide.
Make sure you have this import:
import org.junit.Test;
instead of:
import org.junit.jupiter.api.Test;
As well as the following annotations on test class if your project is SpringBoot 2:
#SpringBootTest
#RunWith(SpringRunner.class)
I faced the same issue "Error: java.lang.Exception: No runnable methods" in my simple Spring-boot project. I resolved the issue by doing the following steps.
Make sure that the the test class is in src/test/java folder. In my project settings the Test class was in src/test folder.
Make sure that src/test/java is in Java Build Path. Go to Project->properties->Java Build Path ->source and add src/test/java folder.
Test class should be in same package as the source Java class with main method.
Make sure you import the right package :
import org.junit.runners.Parameterized;
and not the testng package
I was trying to mock final class(AnyFinalClass.java) in junit using JDave in eclipse.
public void setUp() throws Exception {
Mockery mockery = new Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
AnyFinalClass any = mockery.mock(AnyFinalClass.class);
}
I am trying to use jdave-unfinalizer-1.1.jar as javaagent but didnt had any success. I tried multiple things but getting following exception
java.lang.IllegalArgumentException: Cannot subclass final class class AnyFinalClass
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
Can someone who has already tried jdave unfinalizer give me exact step how to make it work on eclipse.
I set following in eclipse.ini file but got the problem
-Xbootclasspath/a:lC:\WS\JunitTesting\jars\asm-3.0.jar
-javaagent:C:\WS\JunitTesting\jars\jdave-unfinalizer-1.1.jar
While running executing the junit, I gave vm argument as
javaagent:C:\WS\JunitTesting\jars\jdave-unfinalizer-1.1.jar
I am not sure what will be the code. jdave is not having the code and its site is pointing to some other site which is not working. Please correct my code or provide your same working code.
Any help is highly appreciated.
from Enhancer.java line 446:
if (TypeUtils.isFinal(sc.getModifiers()))
throw new IllegalArgumentException("Cannot subclass final class " + sc);
I have not worked with JDave but with another mocking frameworks and the only one that allows to mock a final class was powermock
Look also here
In order to get unfinalizer running you have to put -javaagent:path_to_unfinalizer/jdave-unfinalizer-1.1.jar in the VM arguments of the run configuration of the test.
I also had to include several dependencies of jdave-unfinalizer in the classpath of the project from which the tests ar being launched. These are, taken from the maven definitions of jdave:
jdave-core 1.1
cglib-nodep 2.1_3
objenesis 1.0
asm 3.0
asm-commons 3.0
asm-tree 3.0
I'm trying to use EJB 3.1 Embeddable EJBContainer on Glassfish 3.1 for integration
testing my EJB's. There's a classloading issue I can't figure out.
My ejbs are build into dum-ejb.jar. They use EclipseLink JPA. I also create EJB client jar dum-ejb-client.jar, while attempting to fight the classloading issues. Client jar contains the EJB interfaces, and Entity classes (which are usually parameters or returns values). Client jar also contains a lot of unneeded classes that could be dropped (but I don't see how it would solve the problem).
The problem is that since EclipseLink does bytecode weaving to the Entity classes, the Entity classes must not be in the classpath when the junit tests are run: http://www.java.net/forum/topic/glassfish/glassfish/embedded-glassfish-and-weaving
I can do that and configure classpath so that dum-ejb.jar is not included. If I use EJBContainer so that I look up my service as a java.lang.Object and call it's methods via reflection, the test works. But of course, that's not how I want to write my tests.
Typical test would be like:
#Test
public void testInEJBContainer() throws Exception {
File ejbJarFile = new File("target/dum/dum-ejb.jar");
Map props = new HashMap();
props.put("org.glassfish.ejb.embedded.glassfish.instance.root",
"target/classes/instance-root");
props.put(EJBContainer.MODULES, new File[]{ejbJarFile});
EJBContainer container = EJBContainer.createEJBContainer(props);
CompanyService = (CompanyService)
container.getContext().lookup("java:global/dum/CompanyServiceImpl");
log.info("result of findAll() " + service.findAll(false));
}
How could I run the test if CompanyService interface, and returned Company Entity classes can not be in the classpath?
Even if dum-ejb.jar is not on classpath, and dum-ejb-client.jar is, EclipseLink weaving gets broken.
Isn't this exactly the typical use case for EJBContainer, shouldn't there be a simple solution to this?
Turns out I ran into classloading problems since I was running the EJBContainer from maven ear project.
When I run it from the maven ejb project itself, there's no such issues and EJBContainer is easy to use.