junit4

Android Espresso how to write tests using apk?

假装没事ソ 提交于 2019-12-08 11:35:12
问题 I am a robotium user now switching to Espresso can anyone tell me how to write tests using apk in espresso, as we do in robotium without having acccess to the code but using app apk. And how to access views without R.id.viewid in espresso? as we do in robotium solo.getview("viewidText") In robotium this is how we do public class CoreTest extends ActivityInstrumentationTestCase2 { private Solo solo; //class name of the app launcher activity private static final String LAUNCHER_ACTIVITY_FULL

Unit testing static method which uses a resource bundle

只愿长相守 提交于 2019-12-08 08:04:20
问题 Ive read so many articles on using Powermock and Mockito and tried so many different ways, but I still cant figure out the way to unit test the below static method. public static Map<String, String> getEntries() { Map<String, String> myEntriesMap = new TreeMap<String, String>(); ResourceBundle myEntries = ResourceBundle.getBundle(ENTRIES_BUNDLE); Enumeration<String> enumList = myEntries.getKeys(); String key = null; String value = null; while (enumList.hasMoreElements()) { key = enumList

Any annotation to mark a class as a testclass?

我们两清 提交于 2019-12-08 05:20:53
问题 I am new to Junit4, I am wondering if there is some annotations to mark a class as a test class just like using @Test to mark a method as a test method. 回答1: You can use @Category annotation at class level, like: @Category({PerformanceTests.class, RegressionTests.class}) public class ClassB { @Test public void test_b_1() { assertThat(1 == 1, is(true)); } } I quoted this example from https://www.mkyong.com/unittest/junit-categories-test/ Also if you run Spring tests, Mockito test with JUnit,

Espresso How to access views without using R.id.viewid as we do in robotium?

放肆的年华 提交于 2019-12-08 05:04:37
问题 I am switching from robotium to espresso, I am writing tests using apk , I dont have access to code. In robotium using solo.getView("view-id") we can access the view but I am not geting how to do it in espresso? espresso witId() method needs R.id.viewid which I dont have access. public class AaEspressoTest { private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.tri.re.CordActivity"; private static Class<?> launcherActivityClass; static { try { launcherActivityClass = Class

Issue with @Transactional annotations in Spring JPA

試著忘記壹切 提交于 2019-12-08 04:52:44
问题 I have a doubt related to transactions within transactions. For background, I have a School entity object which has Set of Students entity object mapped to it. I am using Spring Data JPA which is taking care of all the crud operations. I have a SchoolManagementService class which has @Transactional(readonly=true) set at the class level and for all updating methods I am using @Transactional over them. In my SchoolManagementService class I have a method deleteStudents(List) which I have marked

Managing checked exceptions in different JUnit tests

99封情书 提交于 2019-12-07 20:45:09
问题 I am writing a Java Unit test for one of my method. The method declaration is like this: public int convertToInteger() throws InvalidRomanNumberException { int result=0; BaseRomanNumeral num1, num2; int i=0; if(!validOperation()) throw new InvalidRomanNumberException(); } Now I am trying to write two unit tests. One is to test if the right exception is thrown. Another one is to make sure that that the write conversion happens. This is how my test case looks @Test public void

SpringJUnit4ClassRunner initialize beans for each test?

吃可爱长大的小学妹 提交于 2019-12-07 13:55:01
问题 The following test illustrates that this test bean is initialized twice by Spring. I'm hoping someone can tell me why this is so, since it should only be once. Here's the test: import org.apache.log4j.Logger; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.InitializingBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)

mvc controller test with session attribute

偶尔善良 提交于 2019-12-07 12:21:14
问题 I'm trying to test a method with this signature: @Autowired HttpSession http_Session; @RequestMapping(method=RequestMethod.GET, value="/search/findByName") public @ResponseBody List<Map> search(@RequestParam(value="name", required=true) String name){ Integer user_id = http_Session.getAttribute("userinfo"); } userinfo is a class which contains informations about the user and set in session scope when the user logged in.but when I try the test : @RunWith(SpringJUnit4ClassRunner.class)

In Eclipse, how do I see the input to Assert.assertEquals when it fails?

[亡魂溺海] 提交于 2019-12-07 12:21:05
问题 I'm not much of an Eclipse guru, so please forgive my clumsiness. In Eclipse, when I call Assert.assertEquals(obj1,obj2) and that fails, how do I get the IDE to show me obj1 and obj2? I'm using JExample, but I guess that shouldn't make a difference. Edit : Here's what I see: (source: yfrog.com) . 回答1: If the information in the JUnit view is not enough for you, you can always set a exception breakpoint on, for example, java.lang.AssertionError. When running the test, the debugger will stop

How to test whether a method has been overriden in junit?

99封情书 提交于 2019-12-07 10:10:34
问题 I have this question, is there a test annotation or assertion which can tell if a method has been overriden in junit? I'm currently implementing a test case which should tell whether the class Foo 's method toString() has overriden its super class. Thanks. 回答1: you could do it like this probably: class.getMethod("toString").getDeclaringClass(); Here is a sample: class Test { public String toString(){ return "From test"; } } public static void main(String[] args) throws NoSuchMethodException,