Testing Custom Devise Views in Rails 3 w/ Capybara Request Specs & It Is Not Using the New Custom View
Date : March 29 2020, 07:55 AM
Any of those help When you override the Devise controllers, be sure to also override the devise_for routes. For example (in routes.rb): devise_for :users, :controllers => { :registrations => 'registrations' }
|
Robolectric inflating custom views for tests
Date : March 29 2020, 07:55 AM
To fix this issue I'm trying to write some tests for a custom view, but I am having trouble inflating the custom view in my test case. The error I get is , OK, 1 year later but here is the weird thing that worked for me: MyCustomView mView = (MyCustomView) LayoutInflater
.from(RuntimeEnvironment.application)
.inflate(R.layout.my_custom_view_layout,
new MyCustomView(RuntimeEnvironment.application),
true);
|
Testing Views of a Fragment with Robolectric 3.0
Date : March 29 2020, 07:55 AM
Hope that helps Here you add your login fragment on an AppCompactActivity initialized by the startFragment method @Test
public void loginFragmentShouldNotBeNull() {
LoginFragment loginFragment = new LoginFragment();
startFragment(loginFragment, AppCompatActivity.class);
assertNotNull(loginFragment);
}
@Test
public void shouldHaveUserNameEntry() throws Exception {
EditText nameEntry = getEditText(activity,R.id.user_name);
assertViewIsVisible(nameEntry);
assertThat(nameEntry.getHint().toString(),equalTo(ResourceLocator.getString(R.string.login_username)));
}
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class,sdk = 21)
public class LoginFragmentTest {
private LoginFragment mLoginFragment = new LoginFragment();
@Before
public void setUp() throws Exception {
SupportFragmentTestUtil.startVisibleFragment(mLoginFragment);
}
@Test
public void shouldHaveUserNameEntry() throws Exception{
EditText nameEntry = mLoginFragment.getActivity().findViewById(R.id.user_name);
assertViewIsVisible(nameEntry);
assertThat(nameEntry.getHint().toString(),equalTo(RuntimeEnvironment.application.getResources().getString(R.string.login_username)));
}
|
Robolectric 2.0 not creating views when testing
Date : March 29 2020, 07:55 AM
|
Testing custom views with Robolectric: Width and height are always 0
Date : March 29 2020, 07:55 AM
|