2012-02-21 32 views
0

我刚开始使用Robotium & Junit来测试一个android应用程序。跨多种配置(肖像和风景)的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); 
} 

有没有这样的事情,我可以在EclipseJava/Robotium呢?

回答

0

是的,你可以使用Robotium和Java来做到这一点。你会做什么是创建两种测试方法。你必须用“测试”开始他们,所以在你的情况下,它将是testDivideTest1()和testDivideTest2()...一旦你创建了方法,你将在测试开始时使用setActivityOrientation(int orientation)方法。所以,你的测试可能是这个样子:

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,你就可以访问它。