When I run a simple example like the eclipse plug-in test, I get the following error:
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test], {ExactMatcher:fDisplayName=test(ru.cft.platform.deployment.ui.plugin.reverse.qqq)], {LeadingIdentifierMatcher:fClassName=ru.cft.platform.deployment.ui.plugin.reverse.qqq,fLeadingIdentifier=test]] from org.junit.internal.requests.ClassRequest#310850ef
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:80)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:71)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:181)
at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness.lambda$0(PlatformUITestHarness.java:43)
at java.lang.Thread.run(Thread.java:745)
If I run the example as a normal junit test, then everything runs without problems.
What am I doing wrong? There is a need to run it through JUnitPlatform, to use the Suite.
Edit:
package sss;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
#RunWith(JUnitPlatform.class)
public class test {
#Test
#DisplayName("My First Test")
public void test() {
fail("Not yet implemented");
}
}
Related
I have a deployment of a spring-based corporate project, I did everything and now I just need to run the data seeding script, but I don’t understand how to do it at all
The instructions say:
Run test build io.groobit.utils.mock_data_init.ScenarioTest#scenario1
run mock-init.jar in folder (not used run test in "Itelij idea" To avoid such an error .. see image)
Run build mock-init.jar "java -jar mock-init.jar"
I have run tests many times in intelij idea by clicking the desired method in the test folder, but how to proceed here in the command to call it?
package io.groobit.utils.mock_data_init;
import io.groobit.api.client_api.dto.BusinessClientBasicInfo;
import io.groobit.api.client_api.dto.Payment;
import io.groobit.utils.mock_data_init.*;
import io.groobit.utils.mock_data_init.utils.AuthUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import java.math.BigDecimal;
import java.time.Instant;
#Slf4j
#Disabled
#SpringBootTest
#DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
#TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ScenarioTest {
#Test
public void scenario1() throws Exception {
//call this it
}
}
Path test: src/test/java/io/company/utils/mock_data_init/ScenarioTest.java
Any idea?
I've got a Suite class as follows:
package test.suite;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.SuiteDisplayName;
import org.junit.runner.RunWith;
#RunWith(JUnitPlatform.class)
#SuiteDisplayName("JUnit Platform Suite Demo")
#SelectPackages("test")
public class Suite {
}
And two identical test classes (they differ only by their name at the moment) in the same package called test:
package test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class testClass1 {
#Test
void mainA() {
assertTrue(42==42);
}
When I hit run on 'Suite', only testClass1 will be tested and testClass2 is left out. What am I missing?
The Suite should test classes even recursively from other subpackages in the given package if I'm not mistaken.
--EDIT:
Initially I created two test classes for the same class, and the second test class gets ignored. If I add a third test class in the package, but this time for a separate class, that will get tested as expected.
I was experiencing same issue. I had several files and in my case when i do run as suite some of them would be included and other would not. It was pretty frustrating as I can run them fine individually.
It turned out the one that were not included were those whose name did not end with Test. For example, ClassA wouldn't be added but once i renamed to ClassATest it got added when running as suite package feature.
I have two TestNG classes containing a few #Test annotations, nothing fancy, and test methods just under them. When I select both of my class files in Eclipse, right-click, choose TestNG - Convert to TestNG, I am presented with a refacotoring wizard in Eclipse to create said testng.xml suite. But when I cliked Next, I'm asked to refactor my code and include org.testng.AssertJUnit.
Why JUnit? What does JUnit have to do with this?
Here's a code sample:
package seleniumTestovi.Pages; import org.testng.Assert;
import org.testng.annotations.Test;
public class NewTest {
#Test
public void foo() {
Assert.assertTrue(true);
}
}
And here is the code Eclipse wants me to refactor when i try to create testng.xml suite.
package seleniumTestovi.Pages;
import org.testng.annotations.Test;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
public class NewTest {
#Test
public void foo() {
AssertJUnit.assertTrue(true);
}
}
I'm trying to figure out the reason of why I'm getting errors when I'm trying to run some tests that were created and did run a while back. This is the Test class:
package com.chw.pxi.impl.oneway.formatter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
public class OnewayOldFormatterTestsWhy
{
#Before
public void setUp()
{
}
#Test
public void
test_nothing()
{
System.out.println("Yep");
}
}
Here is the error when I try to run the "test_nothing" method by right-click, choose "Run As/Junit test".
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test_nothing], {ExactMatcher:fDisplayName=test_nothing(com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy)], {LeadingIdentifierMatcher:fClassName=com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy,fLeadingIdentifier=test_nothing]] from org.junit.internal.requests.ClassRequest#3632be31
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
There are lots of jar files in the build path for this project. I guess I should try creating a new project and see if the problem follows. A side note - when I run a test on a method in another test that has this - it runs fine without the error above:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations={"dao-tests-context.xml"})
#TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
//Note: This is a live database test but transactions will be rolled back
//except those that invoke methods that require new transactions
public class AgencyDaoTests
If there is additional information needed, please let me know what and how I can go about and get that information for you.
Thanks, Michael
As for 'org.powermock:powermock-api-mockito2:1.6.5' version of Powermock I managed this to work by moving #PrepareForTest annotation from method level to class level.
Im trying to use PowerMock with Mockito, but PowerMock.replayAll(); and PowerMock.verifyAll(); is not found in my Eclipse environment. Used this download link:
http://code.google.com/p/powermock/downloads/detail?name=powermock-mockito-junit-1.5.zip&can=2&q=
And downloaded EasyMock here:
http://sourceforge.net/projects/easymock/files/EasyMock/3.1/easymock-3.1.zip/download
Added all the jars to my libs directory (removed it from my build path). Anyone? Thanks!
Source code Android project and test project:
https://github.com/powder366/test
https://github.com/powder366/testtest
example.
package com.test
import static org.junit.Assert.*;
import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.PowerMockUtils;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(Greeter.class)
public class MockStaticExampleTest {
#Test
public void mockStaticExample() throws Exception {
String expectedGreeting = "greeting";
String nameToGreet = "name";
PowerMockito.mockStatic(Greeter.class);
EasyMock.expect(Greeter.getGreeting(nameToGreet)).andReturn(expectedGreeting);
PowerMock.replayAll();
String actualGreeting = Greeter.getGreeting(nameToGreet);
PowerMock.verifyAll();
assertEquals("Expected and actual greeting did not match", expectedGreeting, actualGreeting);
}
}
You have not to add your jars to the Eclipse build path, but you have to place the jars inside the libs folder. ADT will do what takes to import it.
I finally downloaded:
http://code.google.com/p/powermock/downloads/detail?name=powermock-easymock-1.5-full.jar&can=2&q=
and it worked with PowerMock.replayAll(); and PowerMock.verifyAll();