junit

Terminated test status without any failure message in Android Studio 2.0 while unit testing

戏子无情 提交于 2020-01-04 03:01:08
问题 Issue: I upgraded to Android Studio 2.0 from 1.5 yesterday on Ubuntu. When I unit-test in Android Studio 2.0, it shows Terminated test status even though all tests are passed. Sometimes it shows only some of the tests passed. I'm pretty sure my code is working and tests are correct, because I had same setup on Android Studio 1.5. For example I have 22 tests. Sometimes it shows all 22 tests passed, on the next run it shows 21 of 22 tests passed, sometimes Stopped. 20 of 22 tests passed, other

How to unit test Log.e in android?

柔情痞子 提交于 2020-01-04 02:45:09
问题 I need to perform an unit test where I need to check if an error message is logged when a certain condition occurs in my app. try { //do something } catch (ClassCastException | IndexOutOfBoundsException e) { Log.e(INFOTAG, "Exception "+e.getMessage()); } How can I test this? I am getting the below error while unit testing. Caused by: java.lang.RuntimeException: Method e in android.util.Log not mocked. 回答1: There are two ways to do this: You turn to Powermock or Powermokito; as those mocking

Gradle java.util.logging.Logger output in unit tests

 ̄綄美尐妖づ 提交于 2020-01-04 01:29:08
问题 Sorry, this is probably a very simple question. I am using gradle for my development environment. It works quite well! I have written a simple unit test that uses HtmlUnit and my own package. For my own package, I use java.util.Logger . HtmlUnit seems to use commons logging. I would like to see console output of my logging messages from java.util.Logger However, it seems that even messages at the info level are not displayed in my Unit Test Results GUI (System.err link), although the HtmlUnit

Junit: How to test a method that read properties from a property file

大城市里の小女人 提交于 2020-01-03 21:08:43
问题 Hi I have a class ReadProperty which has a method ReadPropertyFile of return type Myclass which read the parameter values from a property file and return Myclass object. I need help to test the ReadPropertyFile method with JUnit , if possible with mock files and mock object. Here is my code. import java.io.FileInputStream; import java.util.Properties; public class ReadProperty { public Myclass ReadPropertyFile(String fileName) { Myclass myclass = null; String testparam = null; FileInputStream

Robolectric junit test - missing internet permission

╄→гoц情女王★ 提交于 2020-01-03 20:03:01
问题 I am developing some JUnit test for ma app. I need to use Robolectric + Roboguice libraries. What I am trying to do now is only simple test which checks if activity is not null. Here is my code: @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP, application = TestBoomerangManagerApplication.class, manifest = "src/main/AndroidManifest.xml") public class SimpleTest { private DirectInviteEmployeesActivity activity; @Before

JUnit. Parallel running. But all the test methods processing singleton instance. How to solve?

◇◆丶佛笑我妖孽 提交于 2020-01-03 19:43:25
问题 So, I have a couple of JUnit classes, each one contains a list of test methods. Each method is independent of each other, there is no direct connection. But we have indirect connection: all methods processes one singleton object (it is Selenium Web Driver Instance, yes, I use 1 Web Driver Instance for all my tests, because for making new object instance we spend a really lot of time! ). And It is all ok, when test methods execute step by step in one thread. But it is too long too, So, I

How to unit test Spring IntegrationFlow?

微笑、不失礼 提交于 2020-01-03 19:07:10
问题 I have been using Spring Integration DSL to implement some messaging processing flow. How can I actually unit test a single IntegrationFlow, can anyone provide me with an example on how to unit test i.e. transform part of this bean: @Bean public IntegrationFlow transformMessage(){ return message -> message .transform(new GenericTransformer<Message<String>, Message<String>>() { @Override public Message<String> transform(Message<String> message) { MutableMessageHeaders headers = new

Is it possible to disable log4j exception output during jUnit tests run?

我怕爱的太早我们不能终老 提交于 2020-01-03 16:59:06
问题 Need to disable log4j output to console during jUnit tests running but all other log4j output should be enable. There are lot exceptions during testing while checking method reaction on incorrect argument, so exception is ok. 回答1: Create a new log4j properties file called e.g. log4j-test.properties with logging disabled. In your surefire config in the POM, add argLine with -Dlog4j.configuration=log4j-test.properties . 回答2: I know this question is quite old, but still relevant in my opinion,

Is it possible to disable log4j exception output during jUnit tests run?

一笑奈何 提交于 2020-01-03 16:58:13
问题 Need to disable log4j output to console during jUnit tests running but all other log4j output should be enable. There are lot exceptions during testing while checking method reaction on incorrect argument, so exception is ok. 回答1: Create a new log4j properties file called e.g. log4j-test.properties with logging disabled. In your surefire config in the POM, add argLine with -Dlog4j.configuration=log4j-test.properties . 回答2: I know this question is quite old, but still relevant in my opinion,