We can also scrap the TestTemplate which we are using. This template
basically does a server login, test execution, server logout, test
execution.

We can easily do that with TestNG dependencies.

e.g.

public class LoggedInTest {

    @Test
    public void *login*(){
        System.out.println("logged in");
    }

    @Test
    public void logout(){
        System.out.println("logged out");
    }
}

public class ServiceListingTest extends LoggedInTest {

    @Test (*dependsOnMethods* = "*login*", groups = "appserver")
    public void listServices(){

        System.out.println("++++++ Service List +++++");
        System.out.println("Foo.aar");
        System.out.println("Bar.aar");
    }
}


The above setup will ensure that the listServices test runs only after the
login test.


On Tue, Dec 13, 2011 at 8:15 PM, Afkham Azeez <az...@wso2.com> wrote:

> Let me give you a concrete example of how this will make testing very easy
> in our products.
>
> Before running any tests, we need to extract the binaries, copy artifacts,
> then start the Carbon servers. Next we need the tests to run and finally
> shutdown the servers. This is very difficult to do with JUnit in a
> straightforward manner. This is the reason why different product teams have
> incorporated various hacks to do this. With TestNG it is very simple.
>
> We will have a StartupUtil as follows;
>
> public class StartupUtil {
>
>     *@BeforeGroups*(value = {"*appserver*", "*esb*"})
>     public void startup(){
>           extractBinaries();
>           copyArtifacts();
>           startServers();
>      }
>
>     @*AfterGroups*(value = "*appserver*", "*esb*")
>     public void shutdown(){
>         stopServers();
>      }
> }
>
>
> Our test classes will look like the following.
>
>
> public class TestNGSimpleTest {
>     int testInt;
>
>     @BeforeSuite
>     public void beforeSuite(){
>         System.out.println("Before suite");
>     }
>
>     @AfterSuite
>     public void afterSuite(){
>         System.out.println("After suite");
>     }
>
>     @BeforeMethod
>     public void setUp() {
>         testInt = 0;
>         System.out.println("=========>" +
> System.getProperty("sec.verifier.dir"));
>     }
>
>     @AfterMethod
>     public void tearDown() {
>         testInt = 0;
>         System.out.println("=========>" +
> System.getProperty("sec.verifier.dir"));
>     }
>
>     @Test(groups = {"*appserver*"})
>     public void addTest() {
>         testInt++;
>         assert testInt == 1;
>         System.out.println("add test");
>     }
>
>     @Test(groups = {"*appserver*"})
>     public void subtractTest() {
>         testInt--;
>         assert testInt == -1;
>         System.out.println("subtract test");
>     }
> }
>
>
> Take note of the groups concepts & BeforeGroups/AfterGroups annotations.
> We may need a week's worth of effort to migrate all our tests but it will
> be well worth the effort.
>
> If there are no objections, I can start implementing this for
> carbon/core/integration.
>
>
>
> On Tue, Dec 13, 2011 at 7:56 PM, Afkham Azeez <az...@wso2.com> wrote:
>
>> Folks,
>> I was playing around a bit with TestNG (
>> http://testng.org/doc/documentation-main.html#introduction) & it seems
>> to be the way to go for the type of integration testing we are doing. This
>> may involve major changes at the platform testing level but will be worth
>> the investment.
>>
>> Here are some articles that compare TestNG with JUnit4. We are using
>> JUnit 3.
>>
>> http://www.mkyong.com/unittest/junit-4-vs-testng-comparison/
>> http://nelz.net/2010/10/06/testng-vs-junit4/
>>
>> I had a chat with Krishantha & he too agrees that TestNG is more suitable
>> for the type of test automation we do. Does anybody have any concerns
>> regarding this move?
>>
>> --
>> *Afkham Azeez*
>> Director of Architecture; WSO2, Inc.; http://wso2.com
>> Member; Apache Software Foundation; http://www.apache.org/
>> * <http://www.apache.org/>**
>> email: **az...@wso2.com* <az...@wso2.com>* cell: +94 77 3320919
>> blog: **http://blog.afkham.org* <http://blog.afkham.org>*
>> twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
>> *
>> linked-in: **http://lk.linkedin.com/in/afkhamazeez*
>> *
>> *
>> *Lean . Enterprise . Middleware*
>>
>>
>
>
> --
> *Afkham Azeez*
> Director of Architecture; WSO2, Inc.; http://wso2.com
> Member; Apache Software Foundation; http://www.apache.org/
> * <http://www.apache.org/>**
> email: **az...@wso2.com* <az...@wso2.com>* cell: +94 77 3320919
> blog: **http://blog.afkham.org* <http://blog.afkham.org>*
> twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
> *
> linked-in: **http://lk.linkedin.com/in/afkhamazeez*
> *
> *
> *Lean . Enterprise . Middleware*
>
>


-- 
*Afkham Azeez*
Director of Architecture; WSO2, Inc.; http://wso2.com
Member; Apache Software Foundation; http://www.apache.org/
* <http://www.apache.org/>**
email: **az...@wso2.com* <az...@wso2.com>* cell: +94 77 3320919
blog: **http://blog.afkham.org* <http://blog.afkham.org>*
twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
*
linked-in: **http://lk.linkedin.com/in/afkhamazeez*
*
*
*Lean . Enterprise . Middleware*
_______________________________________________
Carbon-dev mailing list
Carbon-dev@wso2.org
http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev

Reply via email to