Android :java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission

I had the same problem, and my code was something like this (for a normal login activity): onView(withId(R.id.username)) .perform(new TypeTextAction(“test_user”)); onView(withId(R.id.password)) .perform(new TypeTextAction(“test123”)); onView(withId(R.id.login)).perform(click()); The last line was crashing with SecurityException. Turned out after the last text typing, the keyboard was left open, hence the next click was considered on a different application. To fix … Read more

Spring not autowiring in unit tests with JUnit

Add something like this to your root unit test class: @RunWith( SpringJUnit4ClassRunner.class ) @ContextConfiguration This will use the XML in your default path. If you need to specify a non-default path then you can supply a locations property to the ContextConfiguration annotation. http://static.springsource.org/spring/docs/2.5.6/reference/testing.html

Spring Boot Microservices – Spring Security – ServiceTest and ControllerTest for JUnit throwing java.lang.StackOverflowError

The error is most likely caused by declaring the AuthenticationManager as a @Bean. Try this in your test class: @MockBean private AuthenticationManager _authenticationManager; That said, the Spring Security team does not recommend exposing the AuthenticationManager in this way, see the comment in Spring issue #29215

Integration tests for AspectJ

Let us use the same sample code as in my answer to the related AspectJ unit testing question: Java class to be targeted by aspect: package de.scrum_master.app; public class Application { public void doSomething(int number) { System.out.println(“Doing something with number ” + number); } } Aspect under test: package de.scrum_master.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import … Read more

How to test methods that call System.exit()?

Indeed, Derkeiler.com suggests: Why System.exit() ? Instead of terminating with System.exit(whateverValue), why not throw an unchecked exception? In normal use it will drift all the way out to the JVM’s last-ditch catcher and shut your script down (unless you decide to catch it somewhere along the way, which might be useful someday). In the JUnit … Read more