Back to project page android-view-selector.
The source code is released under:
Copyright (c) 2013 Nik Haldimann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Soft...
If you think the Android project android-view-selector listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.nikhaldimann.viewselector.android.activities; //from w w w . jav a 2s . co m import static com.nikhaldimann.viewselector.ViewSelectorAssertions.assertThatSelection; import android.app.Fragment; import android.app.FragmentManager; import android.content.Intent; import android.test.ActivityUnitTestCase; import com.nikhaldimann.viewselector.test.HelloWorldExampleActivity; import com.nikhaldimann.viewselector.test.SimpleFragment; /** * Example unit test for a simple fragment. Though creating an activity to fully * start the fragment may not be necessary for most cases. * * Keep this example self-contained so it can be referenced from documentation. */ public class SimpleFragmentTest extends ActivityUnitTestCase<HelloWorldExampleActivity> { public SimpleFragmentTest() { super(HelloWorldExampleActivity.class); } private HelloWorldExampleActivity activity; @Override protected void setUp() throws Exception { super.setUp(); startActivity(new Intent(getInstrumentation().getTargetContext(), HelloWorldExampleActivity.class), null, null); activity = getActivity(); } /** * Adds the fragment to a the activity, thereby fully initializing its view. */ private void startFragment(Fragment fragment) { FragmentManager manager = activity.getFragmentManager(); manager.beginTransaction().add(fragment, null).commit(); manager.executePendingTransactions(); } public void testSimpleFragment() { SimpleFragment fragment = new SimpleFragment(); startFragment(fragment); assertThatSelection("TextView#hello_world", fragment.getView()).hasSize(1); } }