Junit 跨多种配置(纵向和横向)测试 Android

发布于 2025-01-07 20:25:11 字数 413 浏览 4 评论 0原文

我刚刚开始使用 Robotium & Junit 用于测试 Android 应用程序。

我想编写一次测试,然后运行完全相同的测试两次......一次是纵向,一次是横向。

我习惯于 Nunit/C# 具有这样的测试用例属性:

[TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
public void DivideTest(int n, int d, int q)
{
  Assert.AreEqual( q, n / d );
}

我可以在 Eclipse 中使用 Java/Robotium 做类似的事情吗?

I am just starting to use Robotium & Junit to test an android app.

I want to write a test once and then have that exact same test run twice... once in portrait and once in landscape.

I am used to Nunit/C# with test case attributes like this:

[TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
public void DivideTest(int n, int d, int q)
{
  Assert.AreEqual( q, n / d );
}

Is there something like that I can do in Eclipse with Java/Robotium?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2025-01-14 20:25:11

是的,您可以使用 Robotium 和 Java 来完成此操作。您要做的就是创建两个测试方法。您必须以“test”开头,因此在您的情况下,它将是 testDivideTest1() 和 testDivideTest2()...创建方法后,您将使用 setActivityOrientation(intorientation) 方法在测试开始时。因此,您的测试可能如下所示:

TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]

...(Set up methods)...
public void testDivideTest1(int n, int d, int q)
{
  setActivityOrientation(portrait);
  Assert.AreEqual( q, n / d );
}

测试二:

TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
...(Set up methods)...
public void testDivideTest2(int n, int d, int q)
{
  setActivityOrientation(landscape);
  Assert.AreEqual( q, n / d );
}

希望有所帮助。以下是参考链接:http://code.google.com/p/robotium/wiki /QuestionsAndAnswers

此链接包含下载 javadoc 的链接,其中包含所有所需的方法。当您下载 javadoc 时,它将是一个 .jar 文件,因此只需将 .jar 更改为 .zip 即可访问它。

Yes, you can do this using Robotium and Java. What you would do is create two test methods. You have to begin them with "test", so in your case it would be testDivideTest1() and testDivideTest2()... Once you create the methods, you will use the setActivityOrientation(int orientation) method at the beginning of your test. So your test might look something like this:

TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]

...(Set up methods)...
public void testDivideTest1(int n, int d, int q)
{
  setActivityOrientation(portrait);
  Assert.AreEqual( q, n / d );
}

Test two:

TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
...(Set up methods)...
public void testDivideTest2(int n, int d, int q)
{
  setActivityOrientation(landscape);
  Assert.AreEqual( q, n / d );
}

Hope that helps. Here is a reference link: http://code.google.com/p/robotium/wiki/QuestionsAndAnswers

This link has the link to download the javadoc which has all the needed methods. When you download the javadoc, it will a .jar file, so just change the .jar to .zip and you will be able to access it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文