Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Test]
- public async void GetProfileTest ()
- {
- var profileFragment = new ProfileFragment();
- var result = await profileFragment.GetProfileAsync();
- Assert.IsNotNull (result);
- }
- //#define TEST // Uncomment this to start UnitTestig
- . . .
- [ /* Your ActivityAttributes */ ]
- public class YourLauncherActivity : Activity {
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- #if (DEBUG && TEST)
- // Your TestConfiguration.cs Activity
- Intent iTestConfiguration = new Intent(this, typeof(TestConfiguration));
- StartActivity(iTestConfiguration);
- #endif
- #if !TEST
- // Run your normal Activity here, like Login, etc...
- #endif
- }
- }
- ...
- [Activity(Label = "TestConfiguration")]
- public class TestConfiguration : Xunit.Runners.UI.RunnerActivity
- {
- //public static Context Context { get; set; }
- protected override void OnCreate(Bundle bundle)
- {
- // tests can be inside the main assembly
- AddTestAssembly(Assembly.GetExecutingAssembly());
- AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);
- // or in any reference assemblies
- //this.AutoStart = true;
- base.OnCreate(bundle);
- //Context = this;
- }
- }
- public class MyTests
- {
- public MyTests()
- {
- // Before each test
- }
- [Fact]
- public void FailingTest()
- {
- Assert.True(false);
- }
- }
- . . .
- public static TestSuiteInstrumentation CurrentInstrumentation { get; set; }
- public TestInstrumentation(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
- {
- CurrentInstrumentation = this;
- }
- . . .
- [TestFixture]
- public class LoginTests
- {
- private TestSuiteInstrumentation instrument = TestInstrumentation.CurrentInstrumentation;
- private Activity CurrentActivity;
- [SetUp]
- public void SetUp()
- {
- Instrumentation.ActivityMonitor monitor = instrument.AddMonitor($"{instrument.TargetContext.PackageName}." + nameof(Login), null, false);
- Intent intent = new Intent();
- intent.AddFlags(ActivityFlags.NewTask);
- intent.SetClassName(instrument.TargetContext, $"{instrument.TargetContext.PackageName}." + nameof(Login));
- Task.Run(() => instrument.StartActivitySync(intent)).GetAwaiter();
- Activity currentActivity = instrument.WaitForMonitor(monitor);
- }
- [Test]
- public void LoginTest()
- {
- // Verify your activity is not null
- Assert.NotNull(CurrentActivity);
- // Convert CurrentActivity to your Activity
- Login login = CurrentActivity as Login;
- // Verify your views are not null, finding views in your Activity
- Assert.NotNull(login);
- Assert.NotNull(login.FindViewById<EditText>(Resource.Id.etLoginUsername));
- Assert.NotNull(login.FindViewById<EditText>(Resource.Id.etLoginPassword));
- instrument.RunOnMainSync(() => {
- // Here you can run your UI methods for Views, example
- login.FindViewById<EditText>(Resource.Id.etLoginUsername).Text = "hello";
- login.FindViewById<EditText>(Resource.Id.etLoginPassword).Text = "world";
- });
- // Here will be your assertions
- }
- }
- [Activity( ... , Name ="com.yourpackage.android.Login", ...)]
Add Comment
Please, Sign In to add comment