junit

junit gives error java.lang.NoClassDefFoundError: junit/framework/JUnit4TestAdapterCache

主宰稳场 提交于 2020-01-03 16:53:37
问题 I'm trying to run a simple unit test to my project at https://github.com/cdwijayarathna/oj4j. I added both junit-4.12.jar and ant-junit4.jar to the lib folder. But when I ran "rake run_tests", I'm getting following error at the report location I have given. java.lang.NoClassDefFoundError: junit/framework/JUnit4TestAdapterCache at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass

RuntimeException while using ActivityUnitTestCase, but not while ActivityInstrumentationTestCase2

末鹿安然 提交于 2020-01-03 15:56:22
问题 I am trying to test the MainActvity of an Android application with ActivityUnitTestCase. For some reason, I cannot even start the test, because it fails with the following error trace: java.lang.RuntimeException: Exception during suite construction at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

Injecting test module with dagger2

荒凉一梦 提交于 2020-01-03 13:31:09
问题 I use Dagger2 in my android app. Basically I inject a HttpClient (interface) in MainActivity . @Module public class MainActivityModule{ @Provides public HttpClient providesHttpComponent(){ return new RealHttpClient(); } } @Component( modules = MainActivityModule.class ) public interface MainActivityComponent { public MainActivity injectActivity(MainActivity); } public class MainActivity extends Activity { public void onCreate(Bundle saved){ super.onCreate(); injectDependencies(); } protected

How to inject EasyMock mock into tested class private field

雨燕双飞 提交于 2020-01-03 13:16:08
问题 I'm using EasyMock to create mock that is one of private parameters (without setter) in tested class. I tried using reflection - but it does not work correctly. public class TestedClassTest{ @Test public void test(){ TestedClass instance = new TestedClass(); MockedClass mocked = EasyMock.createMock(MockedClass.class); Data data = new Data(); //Void setter DataType dataType = (myDataType.DataType) EasyMock.anyObject(); mocked.setDataType(dataType); EasyMock.expectLastCall(); //expect EasyMock

How to test spring 5 controllers with Junit5

对着背影说爱祢 提交于 2020-01-03 11:15:43
问题 I'm trying to test my Spring 5 web controllers with JUnit 5. The two way to test controller (as mentionned in spring documentation) always give me null pointer. This is my test class import com.lacunasaurus.gamesexplorer.test.configuration.TestBackEndConfiguration; import com.lacunasaurus.gamesexplorer.test.configuration.TestWebConfig; import org.junit.Before; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.platform.runner.JUnitPlatform;

Spring: Test JSP Output in JUnit Test

隐身守侯 提交于 2020-01-03 10:56:10
问题 We have a API, which returns the JSP as the view, for example: @RequestMapping(value = "/cricket/{matchId}", method = RequestMethod.GET) public String getCricketWebView(HttpServletRequest request, @PathVariable("matchId") Integer matchId, ModelMap mv){ try{ return "webforms/cricket"; }catch(Exception e){ e.printStackTrace(); } return ""; } I wrote a unit test to test this out as follows: @Test public void test_cricket() { try { MvcResult result =this.mockMvc.perform(get(BASE + "/cricket/123")

Jenkins: The result file for the metric 'JUnit' is not valid. The result file has been skipped

…衆ロ難τιáo~ 提交于 2020-01-03 10:45:14
问题 I am getting this error when Jenkins tries to read the result xml file through Junit this is the output > [xUnit] [INFO] - Starting to record. [xUnit] [INFO] - Processing JUnit [xUnit] [INFO] - [JUnit] - 1 test report file(s) were found with the pattern '**\testResults\*.xml' relative to 'C:\Jenkins\jobs\InstantMatcher\workspace' for the testing framework 'JUnit'. [xUnit] [ERROR] - The result file 'C:\Jenkins\jobs\InstantMatcher\workspace\Code\RegressionTest\testResults\result-InstantMatcher

How to find Junit tests that are using a given Java method directly or indirectly

江枫思渺然 提交于 2020-01-03 10:07:27
问题 Assume there are Java project and Junit project in an Eclipse workspace. And All the unit tests are located in the Junit project and dependent on the application Java project. When making changes to a Java method, I need to find the unit tests that are using the method directly or indirectly, so that I can run the corresponding tests locally in my PC before checking into source control. I don't want to run the entire junit project since it takes time. I could use Eclipse call hierarchy to

How to verify if method is called on System under test (not a mock)

不问归期 提交于 2020-01-03 10:02:18
问题 I'm trying to write a unit test that needs to confirm if a method is called or not. I'm using JUnit, Mockito and PowerMock. public class Invoice { protected void createInvoice() { // random stuff here markInvoiceAsBilled("57"); } protected void markInvoiceAsBilled(String code) { // marked as billed } } So, here my system under test is Invoice . I'm running this test: public class InvoiceTest { @Test public void testInvoiceMarkedAsBilled() { Invoice sut = new Invoice(); Invoice sutSpy = spy

How to verify if method is called on System under test (not a mock)

心不动则不痛 提交于 2020-01-03 10:02:09
问题 I'm trying to write a unit test that needs to confirm if a method is called or not. I'm using JUnit, Mockito and PowerMock. public class Invoice { protected void createInvoice() { // random stuff here markInvoiceAsBilled("57"); } protected void markInvoiceAsBilled(String code) { // marked as billed } } So, here my system under test is Invoice . I'm running this test: public class InvoiceTest { @Test public void testInvoiceMarkedAsBilled() { Invoice sut = new Invoice(); Invoice sutSpy = spy