As we have observed, many critical issues were reported at testing phase
when verifying certain features using tenants. With new test framework
4.3.0 release, you can easily execute the same test class with different
users modes, using @Factory and @DataProvider annotations. The test
framework define different users levels and provide TestUserMode enum class
to refer user modes easily. And interestingly, this approach will increase
code coverage numbers by executing untouched code blocks.


   -

   Super Tenant (Super Admin)
   -

   Super Tenant User
   -

   Tenant Admin
   -

   Tenant User


Executing the same tests with different user modes are highly recommended.
You can run the same test class using @Factory TestNG annotation. TestNG
factory is used to create instances of test classes dynamically. This is
useful if you want to run the test class any number of times. For example,
if you have a test to deploy web-service you want to run this test multiple
times with different user modes, then it's easy to use TestNG factory where
you create multiple instances of test class and run the tests. Whereas,
dataprovider is used to provide parameters to a test. If you provide
dataprovider to a test, the test will be run taking different sets of value
each time.

Sample test case with above mentioned annotations as follows -


public class FactorySampleTest { private Integer number;
@Factory(dataProvider = "dataProvider") public FactorySampleTest(int n) {
this.number = n; } @BeforeClass public void initialize() {
System.out.println("Init "); } @DataProvider static public Object[][]
dataProvider() { return new Object[][]{ new Object[]{41}, new Object[]{42},
}; } @Test public void test() { System.out.println(this.number); } }


You can refer complete example code at
https://gist.github.com/krishanthasamaraweera/9193651


Thanks, Krishantha.

-- 
Krishantha Samaraweera
Senior Technical Lead - Test Automation
Mobile: +94 77 7759918
WSO2, Inc.; http://wso2.com/
lean . enterprise . middlewear.
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to