JavaRush /Java Blog /Random-IT /JUnit parte I

JUnit parte I

Pubblicato nel gruppo Random-IT

JUnit :: o come amare il validatore JavaRush

JUnit parte I - 1Brevemente sul perché abbiamo bisogno di questa bestia? JUnit è un framework per testare automaticamente il tuo codice buono o meno buono . Puoi dire: - perché ho bisogno di questo swing, posso testare facilmente e semplicemente il mio buon codice Java. Puoi scrivere molti testi introduttivi, ma io non sono un gran poeta, veniamo al sodo...

Crea un oggetto

E quindi, per testare qualcosa, abbiamo prima bisogno di un oggetto di prova. Abbiamo un compito davanti a noi.
  1. Abbiamo bisogno di un oggetto che memorizzi le informazioni sull'utente.
    1. Id: deve essere conteggiato nell'ordine in cui è stato aggiunto il nuovo utente.
    2. Nome utente.
    3. La sua età.
    4. Sesso Maschio Femmina)
  2. È necessario fornire la memorizzazione di un elenco di utenti.

  3. La classe deve essere in grado di farlo.

    1. Genera un elenco di tutti gli utenti.
    2. Genera un elenco di utenti per sesso (MASCHIO/FEMMINA).
    3. Restituisce il numero di utenti nell'elenco generale e calcola il numero in base al sesso dell'utente.
    4. Calcola l'importo totale in base all'età dell'utente e prendi in considerazione anche il sesso.
    5. Calcolare l'età media, sia complessiva che per genere.
E allora, iniziamo a creare un oggetto... Creiamo una classe Java Userche conterrà i campi:
private int id;
private String name;
private int age;
private Sex sex;
Questo è sufficiente per archiviare i dati dell'utente, vediamo cos'altro è necessario per l'attività. Dobbiamo in qualche modo memorizzare tutti gli utenti, creiamo un campo statico nella nostra classe allUsers, penso che vada bene se lo èMap<Integer, User>
private static Map<Integer, User> allUsers;
Dobbiamo anche in qualche modo assegnare un numero di sequenza agli utenti, creiamo un campo contatore statico che, quando si crea un nuovo utente, assegnerà un numero di sequenza Id all'utente.
private static int countId = 0;
Quindi, sembra che abbiamo risolto i campi, scriviamo un costruttore per il nostro oggetto e getter per i campi id, name, age, sex. Non c'è niente di complicato con heterae, chiediamo aiuto a IDEA , lei non rifiuterà mai e renderemo un po' macchinoso il costruttore. Il progettista sarà in grado di farlo. Inizializza i campi, controlla se esiste un oggetto simile in allUsers, se non esiste un oggetto simile, quindi aumenta il nostro contatore countId++e aggiungilo all'elenco di tutti gli utenti. E inizializza anche il campo allUsers se non è stato ancora inizializzato. Per comodità di ricerca di oggetti identici, ridefiniremo i metodi equals()e hashCode(), ancora una volta chiederemo aiuto alla nostra amata IDEA e confronteremo per campi name, age, sex. Inoltre, creiamo un metodo privato hasUser()che controllerà se tale oggetto è nell'elenco.
@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    User user = (User) o;
    return age == user.age &&
            Objects.equals(name, user.name) &&
            sex == user.sex;
}

@Override
public int hashCode() {

    return Objects.hash(name, age, sex);
}
Alla fine, mi sono ritrovato con un designer come questo.
public User(String name, int age, Sex sex) {
    if (allUsers == null){
        allUsers = new HashMap<>();
    }

    this.name = name;
    this.age = age;
    this.sex = sex;

    if (!hasUser()){
        countId++;
        this.id = countId;
        allUsers.put(id, this);
    }
}
e un metodo di aiuto privato
private boolean hasUser(){
    for (User user : allUsers.values()){
        if (user.equals(this) && user.hashCode() == this.hashCode()){
            return true;
        }
    }
    return false;
}
e anche ridefiniretoString()
@Override
public String toString() {
    return "User{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", age=" + age +
            ", sex=" + sex +
            '}';
}
Ora è il momento di implementare la logica dei metodi richiesti. Poiché la logica funzionerà principalmente con campi statici, renderemo statici anche i metodi; non sono necessari per gli oggetti.
  1. Genera un elenco di tutti gli utenti.
  2. Genera un elenco di utenti per sesso (MASCHIO/FEMMINA).
  3. I punti a e b possono essere gestiti bene con un metodo getAllUsers()che restituirà un elenco di tutti Usere un metodo sovraccaricato getAllUsers(Sex sex)che restituirà un elenco, a seconda del parametro passato Sex.

    public static List<User> getAllUsers(){
        return new ArrayList<>(allUsers.values());
    }
    
    public static List<User> getAllUsers(Sex sex){
        List<User> listAllUsers = new ArrayList<>();
        for (User user : allUsers.values()){
            if (user.sex == sex){
                listAllUsers.add(user);
            }
        }
        return listAllUsers;
    }

  4. Restituisce il numero di utenti nell'elenco generale e calcola il numero in base al sesso dell'utente.

    public static int getHowManyUsers(){
        return allUsers.size();
    }
    
    public static int getHowManyUsers(Sex sex){
        return getAllUsers(sex).size();
    }

  5. Calcola l'importo totale in base all'età dell'utente e prendi in considerazione anche il sesso. Creiamo metodi per questa attività.

    public static int getAllAgeUsers(){
        int countAge = 0;
        for (User user : allUsers.values()){
            countAge += user.age;
        }
        return countAge;
    }
    
    public static int getAllAgeUsers(Sex sex){
        int countAge = 0;
        for (User user : getAllUsers(sex)){
            countAge += user.age;
        }
        return countAge;
    }

  6. Calcolare l'età media, sia complessiva che per genere.

    public static int getAverageAgeOfAllUsers(){
        return getAllAgeUsers() / getHowManyUsers();
    }
    
    public static int getAverageAgeOfAllUsers(Sex sex){
        return getAllAgeUsers(sex) / getHowManyUsers(sex);
    }

    Ottimo, abbiamo descritto l'oggetto richiesto e il suo comportamento. Ora possiamo passare a JUnit , ma prima ti mostrerò come apparirà un semplice test se lo eseguissimo in main .

    public static void main(String[] args) {
        new User("Eugene", 35, Sex.MALE);
        new User("Marina", 34, Sex.FEMALE);
        new User("Alina", 7, Sex.FEMALE);
    
    
        System.out.println("All users:");
        User.getAllUsers().forEach(System.out::println);
        System.out.println("All users: MALE");
        User.getAllUsers(Sex.MALE).forEach(System.out::println);
        System.out.println("All users: FEMALE");
        User.getAllUsers(Sex.FEMALE).forEach(System.out::println);
        System.out.println("================================================");
        System.out.println(" all users: " + User.getHowManyUsers());
        System.out.println(" all MALE users: " + User.getHowManyUsers(Sex.MALE));
        System.out.println("all FEMALE users: " + User.getHowManyUsers(Sex.FEMALE));
        System.out.println("================================================");
        System.out.println(" total age of all users: " + User.getAllAgeUsers());
        System.out.println(" total age of all MALE users: " + User.getAllAgeUsers(Sex.MALE));
        System.out.println("total age of all FEMALE users: " + User.getAllAgeUsers(Sex.FEMALE));
        System.out.println("================================================");
        System.out.println(" average age of all users: " + User.getAverageAgeOfAllUsers());
        System.out.println(" average age of all MALE users: " + User.getAverageAgeOfAllUsers(Sex.MALE));
        System.out.println("average age of all FEMALE users: " + User.getAverageAgeOfAllUsers(Sex.FEMALE));
        System.out.println("================================================");
    }

    L'output sulla console sarà simile a questo, quindi confronteremo se abbiamo ottenuto un funzionamento normale. Naturalmente possiamo andare più in profondità, scrivere una logica di confronto e vedere cosa dice il nostro calcolo, anche se non saremo sicuri di essere stati in grado di provvedere a tutto.

    //output
    Все пользователи:
    User{id=1, name='Eugene', age=35, sex=MALE}
    User{id=2, name='Marina', age=34, sex=FEMALE}
    User{id=3, name='Alina', age=7, sex=FEMALE}
    Все пользователи: MALE
    User{id=1, name='Eugene', age=35, sex=MALE}
    Все пользователи: FEMALE
    User{id=2, name='Marina', age=34, sex=FEMALE}
    User{id=3, name='Alina', age=7, sex=FEMALE}
    ================================================
           всех пользователей: 3
      всех пользователей MALE: 1
    всех пользователей FEMALE: 2
    ================================================
           общий возраст всех пользователей: 76
      общий возраст всех пользователей MALE: 35
    общий возраст всех пользователей FEMALE: 41
    ================================================
           средний возраст всех пользователей: 25
      средний возраст всех пользователей MALE: 35
    средний возраст всех пользователей FEMALE: 20
    ================================================
    
    Process finished with exit code 0

    Non siamo soddisfatti di questo risultato, aboliti i test principali , abbiamo bisogno di JUnit .

Come connettere JUnit a un progetto

Sorge la domanda su come collegarlo al progetto. Per chi lo sapesse, non sceglierò l’opzione con Maven , poiché questa è una storia completamente diversa. ;) Apri la struttura del progetto Ctrl + Alt + Maiusc + S -> Librerie -> fai clic su + (Nuova libreria di progetto) -> seleziona da Maven, JUnit parte I - 2quindi vediamo una finestra del genere, inserisci "junit:junit:4.12" nella barra di ricerca , aspetta finché non trova -> OK! ->Va bene! JUnit parte I - 3Dovresti ottenere questo risultato. JUnit parte I - 4Fai clic su OK, congratulazioni. JUnit è stata aggiunta al progetto. Andiamo avanti. Ora dobbiamo creare test per la nostra classe Java, posiziona il cursore sul nome della classe User -> premi Alt + Invio -> seleziona crea Test. Dovremmo vedere una finestra in cui dobbiamo selezionare la libreria JUnit4 -> selezionare i metodi che testeremo -> OK JUnit parte I - 5L'idea stessa creerà una classe UserTest, questa è la classe in cui copriremo il nostro codice con i test. Iniziamo:

Il nostro primo @Test

Creiamo il nostro primo metodo @TestgetAllUsers() : questo è un metodo che dovrebbe restituire tutti gli utenti. Il test sarà simile a questo:
@Test
public void getAllUsers() {
    // create test data
    User user = new User("Eugene", 35, Sex.MALE);
    User user1 = new User("Marina", 34, Sex.FEMALE);
    User user2 = new User("Alina", 7, Sex.FEMALE);

    //create an expected list and fill it with the data of our method
    List<User> expected = User.getAllUsers();

    //create actual list put data in it for comparison
    //what we expect the method to return
    List<User> actual = new ArrayList<>();
    actual.add(user);
    actual.add(user1);
    actual.add(user2);

    //run the test if the list expected and actual are not equal
    //the test will fail, read the test results in the console
    Assert.assertEquals(expected, actual);
}
Qui creiamo diversi utenti di prova -> creiamo un elenco expected in cui inseriremo gli utenti il ​​cui metodo ci tornerà getAllUsers()-> creiamo un elenco actual in cui inseriremo gli utenti di cui presupponiamo che il getAllUsers()metodo Assert.assertEquals(effettivo, previsto) verranno utilizzati e gli trasmetteremo gli elenchi, controllati e aggiornati. Questo metodo testerà gli oggetti negli elenchi forniti e restituirà il risultato del test. Il metodo confronterà tutti i campi degli oggetti, anche esaminando i campi dei genitori se è presente ereditarietà. Eseguiamo il primo test... JUnit parte I - 6Il test è stato completato con successo. Ora proviamo a far fallire il test, per questo dobbiamo modificare uno degli elenchi di test, lo faremo commentando l'aggiunta di un utente all'elenco actual.
@Test
public void getAllUsers() {
    // create test data
    User user = new User("Eugene", 35, Sex.MALE);
    User user1 = new User("Marina", 34, Sex.FEMALE);
    User user2 = new User("Alina", 7, Sex.FEMALE);

    //create an expected list and fill it with the data of our method
    List<User> expected = User.getAllUsers();

    //create actual list put data in it for comparison
    //what we expect the method to return
    List<User> actual = new ArrayList<>();
    actual.add(user);
    actual.add(user1);
    //actual.add(user2);

    //run the test if the list expected and actual are not equal
    //the test will fail, read the test results in the console
    Assert.assertEquals(expected, actual);
}
eseguiamo il test e vediamo quanto segue: JUnit parte I - 7Ora possiamo esaminare un po' il motivo del fallimento del test. Qui vediamo che ci sono più utenti nell'elenco ispezionato che in quello attuale. Questo è il motivo del fallimento. Possiamo controllarlo in main? JUnit : main = 1 : 0. Vediamo come apparirà il test se contiene oggetti completamente diversi, facciamolo in questo modo:
@Test
public void getAllUsers() {
    // create test data
    User user = new User("Eugene", 35, Sex.MALE);
    User user1 = new User("Marina", 34, Sex.FEMALE);
    User user2 = new User("Alina", 7, Sex.FEMALE);

    //create an expected list and fill it with the data of our method
    List<User> expected = User.getAllUsers();

    //create actual list put data in it for comparison
    //what we expect the method to return
    List<User> actual = new ArrayList<>();
    actual.add(new User("User1", 1, Sex.MALE));
    actual.add(new User("User2", 2, Sex.FEMALE));
    actual.add(new User("User3", 3, Sex.MALE));

    //run the test if the list expected and actual are not equal
    //the test will fail, read the test results in the console
    Assert.assertEquals(expected, actual);
}
Questo è quello che ci sarà nella console: JUnit parte I - 8qui possiamo subito vedere che ci sono diversi utenti nelle liste confrontate, possiamo anche cliccare su <Click per vedere la differenza> otterremo una finestra dove potremo vedere in dettaglio quali dati abbiamo problema con. IDEA metterà in evidenza tutti i campi in cui esistono differenze. JUnit parte I - 9mainpuò succedere? - NO. JUnit : main = 2 : 0 Bene, andiamo avanti, abbiamo ancora un sacco di metodi che devono essere coperti con i test), ma aspetta, non sarà male controllare se il metodo ci tornerà getAllUsers(), perché è così cosa facciamo con nullle attività JavaRush catturate dal validatore). Facciamo così, è questione di tre centesimi...
@Test
public void getAllUsers_NO_NULL() {
    //add check for null
    List<User> expected = User.getAllUsers();
    Assert.assertNotNull(expected);
}
Sì, sì, questo è più o meno il modo in cui il validatore rileva il nostro codice schifosonull ;) Ora eseguiamo questo test e vediamo cosa ci mostra. E mostrerà un errore, come???? Come è stato possibile commettere un errore di test qui))) JUnit parte I - 10E qui possiamo raccogliere i primi frutti coprendo il nostro codice con test. Come ricorderete, allUsers abbiamo inizializzato il campo nel costruttore, il che significa che quando chiamiamo il metodo getAllUsers()faremo riferimento a un oggetto che non è stato ancora inizializzato. Modifichiamolo, rimuoviamo l'inizializzazione dal costruttore e facciamolo quando dichiariamo il campo.
private static Map<Integer, User> allUsers = new HashMap<>();

    public User(String name, int age, Sex sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;

        if (!hasUser()) {
            countId++;
            this.id = countId;
            allUsers.put(id, this);
        }
    }
Facciamo il test, ora va tutto bene. JUnit parte I - 11Non penso che sarà facile catturare NPE in main, penso che sarai d'accordo sul fatto che il conteggio è JUnit: main = 3: 0 Quindi tratterò tutti i metodi con i test e ti farò vedere come apparirà ... Ora la nostra classe di test assomiglia a questa:
package user;

import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class UserTest {

    @Test
    public void getAllUsers() {
        // create test data
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        //create an expected list and fill it with the data of our method
        List<User> expected = User.getAllUsers();

        //create actual list put data in it for comparison
        //what we expect the method to return
        List<User> actual = new ArrayList<>();
        actual.add(user);
        actual.add(user1);
        actual.add(user2);

        //run the test if the list expected and actual are not equal
        //the test will fail, read the test results in the console
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllUsers_NO_NULL() {
        //add check for null
        List<User> expected = User.getAllUsers();
        Assert.assertNotNull(expected);
    }

    @Test
    public void getAllUsers_MALE() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        List<User> expected = User.getAllUsers(Sex.MALE);

        List<User> actual = new ArrayList<>();
        actual.add(user);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllUsers_MALE_NO_NULL() {
        //add check for null
        List<User> expected = User.getAllUsers(Sex.MALE);
        Assert.assertNotNull(expected);
    }

    @Test
    public void getAllUsers_FEMALE() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        List<User> expected = User.getAllUsers(Sex.FEMALE);

        List<User> actual = new ArrayList<>();
        actual.add(user1);
        actual.add(user2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllUsers_FEMALE_NO_NULL() {
        //add check for null
        List<User> expected = User.getAllUsers(Sex.FEMALE);
        Assert.assertNotNull(expected);
    }

    @Test
    public void getHowManyUsers() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        int expected = User.getHowManyUsers();

        int actual = 3;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getHowManyUsers_MALE() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        int expected = User.getHowManyUsers(Sex.MALE);

        int actual = 1;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getHowManyUsers_FEMALE() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        int expected = User.getHowManyUsers(Sex.FEMALE);

        int actual = 2;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllAgeUsers() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        int expected = User.getAllAgeUsers();

        int actual = 35 + 34 + 7;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllAgeUsers_MALE() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        int expected = User.getAllAgeUsers(Sex.MALE);

        int actual = 35;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllAgeUsers_FEMALE() {
        User user = new User("Eugene", 35, Sex.MALE);
        User user1 = new User("Marina", 34, Sex.FEMALE);
        User user2 = new User("Alina", 7, Sex.FEMALE);

        int expected = User.getAllAgeUsers(Sex.FEMALE);

        int actual = 34 + 7;

        Assert.assertEquals(expected, actual);
    }
}
Sì, si è rivelato non piccolo, ma cosa accadrà quando si lavora con progetti di grandi dimensioni. Cosa può essere ridotto qui Dopo aver valutato tutto, puoi vedere che creiamo dati di test in ogni test e qui le annotazioni vengono in nostro aiuto. Prendiamo @Before: l'annotazione @Beforeindica che il metodo verrà eseguito prima di ogni metodo testato @Test. Questo è come apparirà ora la nostra classe di test con annotazione @Before:
package user;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class UserTest {
    private User user;
    private User user1;
    private User user2;

    @Before
    public void setUp() throws Exception {
        user = new User("Eugene", 35, Sex.MALE);
        user1 = new User("Marina", 34, Sex.FEMALE);
        user2 = new User("Alina", 7, Sex.FEMALE);
    }

    @Test
    public void getAllUsers() {
        List<User> expected = User.getAllUsers();

        List<User> actual = new ArrayList<>();
        actual.add(user);
        actual.add(user1);
        actual.add(user2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllUsers_NO_NULL() {
        List<User> expected = User.getAllUsers();
        Assert.assertNotNull(expected);
    }

    @Test
    public void getAllUsers_MALE() {
        List<User> expected = User.getAllUsers(Sex.MALE);

        List<User> actual = new ArrayList<>();
        actual.add(user);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllUsers_MALE_NO_NULL() {
        //add check for null
        List<User> expected = User.getAllUsers(Sex.MALE);
        Assert.assertNotNull(expected);
    }

    @Test
    public void getAllUsers_FEMALE() {
        List<User> expected = User.getAllUsers(Sex.FEMALE);

        List<User> actual = new ArrayList<>();
        actual.add(user1);
        actual.add(user2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllUsers_FEMALE_NO_NULL() {
        //add check for null
        List<User> expected = User.getAllUsers(Sex.FEMALE);
        Assert.assertNotNull(expected);
    }

    @Test
    public void getHowManyUsers() {
        int expected = User.getHowManyUsers();

        int actual = 3;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getHowManyUsers_MALE() {
        int expected = User.getHowManyUsers(Sex.MALE);

        int actual = 1;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getHowManyUsers_FEMALE() {
        int expected = User.getHowManyUsers(Sex.FEMALE);

        int actual = 2;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllAgeUsers() {
        int expected = User.getAllAgeUsers();

        int actual = 35 + 34 + 7;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllAgeUsers_MALE() {
        int expected = User.getAllAgeUsers(Sex.MALE);

        int actual = 35;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void getAllAgeUsers_FEMALE() {
        int expected = User.getAllAgeUsers(Sex.FEMALE);

        int actual = 34 + 7;

        Assert.assertEquals(expected, actual);
    }
}
Beh, e tu, è già più divertente e più facile da leggere ;) Ecco un elenco di annotazioni per JUnit; è sicuramente più facile convivere con loro.
@Test – определяет что метод method() является тестовым.
@Before – указывает на то, что метод будет выполнятся перед каждым тестируемым методом @Test.
@After – указывает на то что метод будет выполнятся после каждого тестируемого метода @Test
@BeforeClass – указывает на то, что метод будет выполнятся в начале всех тестов,
а точней в момент запуска тестов(перед всеми тестами @Test).
@AfterClass – указывает на то, что метод будет выполнятся после всех тестов.
@Ignore – говорит, что метод будет проигнорирован в момент проведения тестирования.
(expected = Exception.class) – указывает на то, что в данном тестовом методе
вы преднамеренно ожидаете Exception.
(timeout = 100) – указывает, что тестируемый метод не должен занимать больше чем 100 миллисекунд.
Principali metodi della classe Assertper il controllo:
fail(String) – указывает на то что бы тестовый метод завалился при этом выводя текстовое сообщение.
assertTrue([message], boolean condition) – проверяет, что логическое condition истинно.
assertsEquals([String message], expected, actual) – проверяет, что два значения совпадают.
Примечание: для массивов проверяются ссылки, а не содержание массивов.
assertNull([message], object) – проверяет, что an object является пустым null.
assertNotNull([message], object) – проверяет, что an object не является пустым null.
assertSame([String], expected, actual) – проверяет, что обе переменные относятся к одному an objectу.
assertNotSame([String], expected, actual) – проверяет, что обе переменные относятся к разным an objectм.
Ecco come possiamo aggiungere la dipendenza JUnit 4.12 in Maven
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>
continua qui -> JUnit parte II
Commenti
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION