Модераторы: LSD, AntonSaburov
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Помогите разобраться с TestNG, плз 
:(
    Опции темы
Den1s
Дата 16.4.2007, 10:33 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 117
Регистрация: 27.10.2005

Репутация: нет
Всего: нет



На оффсайте пример типа Хеллоу Ворлд заставил только  smile 

Есть класс
Код

package com.test;

import com.test.LocalClass1;

public class LocalClass3 extends LocalClass2 {

    /**
     * @param args
     */
    public LocalClass3(int iOne) throws Exception {
        super( iOne );
        String sOne = "sone";
        String sTwo = "stwo";
        String sThree = "sthree";
        String sFour = "sfour";
        setSOne( sOne );
        setSTwo( sTwo );
        setSThee( sThree );
        setSFour( sFour );
    }

    public synchronized String getSSix(int iTwo) throws Exception {
        return super.getSFive( iTwo );
    }

    public synchronized int getIFour(LocalClass1 lc, String sSeven) throws Exception {
        return super.getIThree( sSeven );
    }

}



таким образом есть класс являющийся екстендедом другого класса.

Есть общий шаблон для юнит теста

Код



// TODO rename package.
// I recommend that it be the same as the target class.
// Because, if it isn't same, it can't invoke a package scope methods.
package com.test;

// TODO import the classes which is the targets of a unit testing.
import org.testng.Assert;

/**
 * TODO DOCUMENT ME!
 * <br/> This is the template of a test class for a plain objects like a value object.<br/>
 * <br/> See also:<br/>
 * <a href="http://testng.org/doc/documentation-main.html" target="_new">TestNG documentation</a><br/> 
 * <a * href="http://www-128.ibm.com/developerworks/java/library/j-testng/index.html" target="_new"> TestNG makes Java unit testing a breeze</a><br/>
 * <a href="http://www-128.ibm.com/developerworks/java/library/j-cq08296/index.html" target="_new"> In pursuit of code quality: JUnit 4 vs. TestNG</a>
 * 
 * @author <author>,<br/>Last changed by $Author$
 * @testng.test
 */
// TODO rename this class.
// I recommend "Test" prefix to be put on the testing target class name.
public class TestPlainObject extends Assert {
    /**
     * Initializing this class.<br/>
     * This method is executed only once before all the methods is executed.
     * 
     * @testng.before-class = "true"
     */
    public void setUp() throws Exception {
        // TODO write the initializing codes for this class.
    }

    /**
     * Cleanup this class.<br/>
     * This method is executed only once after all the methods is executed.
     * 
     * @testng.after-class = "true"
     */
    public void tearDown() throws Exception {
        // TODO write the cleanup codes for this class.
    }

    /**
     * Pre-execute codes.<br/>
     * This method is executed every time before each method is executed.
     * 
     * @testng.before-method = "true"
     */
    public void beginTest() throws Exception {
        // TODO write the initializing codes for each method.
    }

    /**
     * Post-execute codes.<br/>
     * This method is executed every time after each method is executed.
     * 
     * @testng.after-method = "true"
     */
    public void endTest() throws Exception {
        // TODO write the cleanup codes for each method.
    }

    // ---- The following is the testing methods. ----

    /**
     * TODO DOCUMENT ME!<br/>
     * This sample is simple codes for a normal case.
     * 
     * @testng.test
     */
    public void testCase01() throws Exception {
        // TODO write the testing codes.
    }

    /**
     * TODO DOCUMENT ME!<br/>
     * This sample is simple codes for a abnormal case.<br/>
     * If the codes threw java.lang.IllegalArgumentException, TestNG accept this case.
     * 
     * @testng.test
     * @testng.expected-exceptions value = "java.lang.IllegalArgumentException"
     */
    public void testCase02() throws Exception {
        // TODO write the testing codes.
    }

    /**
     * A data providor.
     * 
     * @testng.data-provider name = "data1"
     */
    public Object[][] createData() throws Exception {
        return new Object[][] {
        { 1st argument, 2nd argument }
            };
    }

    /**
     * TODO DOCUMENT ME!<br/>
     * This sample is to run with parameters.<br/>
     * Parameters are given by dataProvirer.
     * 
     * @testng.test dataProvider = "data1"
     */
    public void testCase03(final String key, final String key2) throws Exception {
        // TODO write the testing codes.
    }

    /**
     * TODO DOCUMENT ME!<br/>
     * This sample is to run after other methods.<br/>
     * If testCase01 or testCase02 failed, TestNG don't execute this method.
     * 
     * @testng.test dependsOnMethods = "testCase01, testCase02"
     */
    public void testCase04() throws Exception {
        // TODO write the testing codes.
    }
}




подскажите плз хоть как примерно этот юнит тест писать, или дайте плз ссылочки где более сложные примеры рассматриваются? smile 
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "Java"
LSD   AntonSaburov
powerOn   tux
javastic
  • Прежде, чем задать вопрос, прочтите это!
  • Книги по Java собираются здесь.
  • Документация и ресурсы по Java находятся здесь.
  • Используйте теги [code=java][/code] для подсветки кода. Используйтe чекбокс "транслит", если у Вас нет русских шрифтов.
  • Помечайте свой вопрос как решённый, если на него получен ответ. Ссылка "Пометить как решённый" находится над первым постом.
  • Действия модераторов можно обсудить здесь.
  • FAQ раздела лежит здесь.

Если Вам помогли, и атмосфера форума Вам понравилась, то заходите к нам чаще! С уважением, LSD, AntonSaburov, powerOn, tux, javastic.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Java: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.0377 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.