junit4

junit cannot find class

旧巷老猫 提交于 2019-12-25 18:39:43
问题 I am able to run the sample tests supplied with junit (from any directory). I would think that this suggests my installation of junit is perfectly fine. I assume, to compile a junit test, it is no different from any other java file, namely: javac fileName.java My test file (.java and resulting .class) lives in: c:\parent\child. Obviously, in order to compile the .java file, I have a package statement on the first line: package parent.child followed by the all-important: import junit.framework

how to test picasso using unit-test and mockito

有些话、适合烂在心里 提交于 2019-12-25 08:49:52
问题 I am learning how to unit-testing in android studio. as shown below, I would like to test the two methods shown below in the code section. can you please help and guide me how to test this method? code public RequestCreator requestCreatorFromUrl(String mPicUrl) { return Picasso.with(mCtx).load(mPicUrl); } public void setImageOnImageView(RequestCreator requestCreator, ImageView mImagView) { requestCreator.into(mImagView); } My Attempts : @Test public void whenRequestCreatorFromUrlTest() throws

JUnit Tests fail's ramdomly, Camel 2.15.1 Custom TypeConvertor not getting loaded

假如想象 提交于 2019-12-25 04:29:41
问题 JUnit Tests fail's randomly, Camel 2.15.1 Custom TypeConverter not getting loaded. I am currently having issues with custom TypeConverter not getting loaded, Unit tests are failing randomly. When I am trying to run them multiple times, sometimes the TypeConverter gets loaded and Unit Test pass and work as expected. Sometimes the TypeConverter is not found. message=exception: org.apache.camel.InvalidPayloadException: No body available of type: org.apache.commons.httpclient.methods

Print Test Result in JUnit

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 01:02:05
问题 Currently I am making the test case repeat 2 times, so how do I print the results as 2 separate results. I tried using the built-in function to create the text, however, it does now show either "Success" or "Failure". Currently I have this code: public class UnitTestRunner { static JUnitCore junitCore; static Class<?> testClasses; public static void main(String[] args) { System.out.println("Running Junit Test Suite."); Result result = JUnitCore.runClasses(TestSuite.class); for (Failure

Error when running JUnit Tests from DOS Command line

只谈情不闲聊 提交于 2019-12-24 21:34:19
问题 My projects is running on a Windows 2008 Server. My project source code sit in the following folders: com.company.division.dao com.company.division.entity com.company.division.main com.company.division.junit My junit test class are in the folder C:\Sample\com\company\division\junit. I am using JUnit 4.11 When I run this from Eclipse it runs fine. I have tried the following from DOS command line: First I cd C:\Sample\com\company\division\junit\ From C:\Sample\com\company\division\junit> where

How can I test an old Spring 2.0.7 application with JUnit?

给你一囗甜甜゛ 提交于 2019-12-24 20:21:39
问题 I have an old app built with an ancient version of Spring: 2.0.7. I have been tasked with adding new functionality to this app, so I'm required to write some JUnit tests too. So far, I have writen mockup classes for my services, and an applicationContext-test.xml file placed under src/test/resources/ . Typically, the next step would be to write my test case like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/applicationContext-test.xml"}) public class

Sonarqube test case rule does not take @Test annotation into account

我的未来我决定 提交于 2019-12-24 14:18:35
问题 Sonarqube generates issues as TestCases should contain tests regarding that test classes does not have any tests inside but there are methods marked with @Test annotation and classes annotated with @RunWith(SpringJunit4ClassRunner.class) . I have no problem running TestSuites and importing unit test and coverage reports into sonarqube. I checked sonarqube source code and it should find annotations but unfortunately it does not. Rule id for the mentioned issue is S2187. Is there a

Play 2.5.x junit test error handling with fakeRequest

本秂侑毒 提交于 2019-12-24 10:58:54
问题 My program uses global error handling. When i using fakeRequest() to test, it throws out exception instead of trigger my error handler. Am I missing some configuration? Or how can I test my global error handler. Below is my current code: Controller: public class MyController { public Result MyService() { if (true) throw new RuntimeException("exception"); } } ErrorHandler: @Singleton public class MyErrorHandler extends DefaultHttpErrorHandler { @Inject public MyErrorHandler (Configuration

H2 database org.h2.Driver ClassNotFoundException

廉价感情. 提交于 2019-12-24 10:05:55
问题 I try to run JUNIT test with eclipse and ANT they both are complainen that org.h2.Driver class is not found. I have h2-1.3.164.jar in my classpath and for proof about it here is classpath from system property java.class.path c:\trasferer\build; C:\Program Files (x86)\IBM\IMShared\plugins\org.junit4_4.3.1\junit.jar; c:\trasferer\lib\ojdbc6.jar; c:\trasferer\lib\sqljdbc4.jar; c:\trasferer\lib-test\h2-1.3.164.jar; c:\trasferer\lib-test\junit-4.8.2.jar; c:\trasferer\lib-test\log4j-1.2.14.jar; c:

How to simulate caught and logged exceptions inside a method and create JUnit tests

我只是一个虾纸丫 提交于 2019-12-24 09:17:11
问题 I have to write JUnit test cases for existing code where I do not have the liberty / opportunity to re-write the actual code. In many of these classes, the methods catch an exception internally and just log it. And the exceptions are not based on any parameters which could be manipulated to attempt to throw the exception, but are thrown by the code inside the method - e.g. - the method may open a file and catch IOException and just log it. Basically, many of the methods just eat all the