-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint_6 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Sprint_6 #5
Changes from all commits
eaf60b0
975e933
2740e5b
9f9be26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| # qa_java | ||
|
|
||
| QA Java Project |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,19 +5,20 @@ | |
| public class Lion { | ||
|
|
||
| boolean hasMane; | ||
| //Делаю инъекцию зависимости через конструктор, как было показано на вебинаре | ||
| Feline feline; | ||
|
|
||
| public Lion(String sex) throws Exception { | ||
| public Lion(String sex, Feline feline) throws Exception { | ||
| this.feline = feline; | ||
| if ("Самец".equals(sex)) { | ||
| hasMane = true; | ||
| } else if ("Самка".equals(sex)) { | ||
| hasMane = false; | ||
| } else { | ||
| throw new Exception("Используйте допустимые значения пола животного - самей или самка"); | ||
| throw new Exception("Используйте допустимые значения пола животного - самец или самка"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отлично! Изоляция выполнена верно. |
||
| } | ||
| } | ||
|
|
||
| Feline feline = new Feline(); | ||
|
|
||
| public int getKittens() { | ||
| return feline.getKittens(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ public interface Predator { | |
|
|
||
| List<String> eatMeat() throws Exception; | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import com.example.Cat; | ||
| import com.example.Feline; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class CatTest { | ||
|
|
||
| @Mock | ||
| Feline feline; | ||
|
|
||
|
|
||
| @Before | ||
| public void init() { | ||
| MockitoAnnotations.initMocks(this); | ||
| } | ||
|
|
||
| @Test | ||
| public void getCatSoundTest() { | ||
| Cat cat = new Cat(feline); | ||
| String expectedSound = "Мяу"; | ||
| assertEquals("Кошка должна мяукать", expectedSound, cat.getSound()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getCatFoodTest() throws Exception { | ||
| Cat cat = new Cat(feline); | ||
| List<String> expectedFood = List.of("Животные", "Птицы", "Рыба"); | ||
| Mockito.when(feline.eatMeat()).thenReturn(expectedFood); | ||
| assertEquals("Кошка должна есть мясо", expectedFood, cat.getFood()); | ||
| Mockito.verify(feline, Mockito.times(1)).eatMeat(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отлично! Уместно применен verify. |
||
| } | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import com.example.Feline; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class FelineTest { | ||
|
|
||
|
|
||
| @Test | ||
| public void getFelineFood() throws Exception { | ||
| Feline feline = new Feline(); | ||
| List<String> actualFood = List.of("Животные", "Птицы", "Рыба"); | ||
| Assert.assertEquals(actualFood, feline.getFood("Хищник")); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFelineFamily() { | ||
| Feline feline = new Feline(); | ||
| String actualFamily = feline.getFamily(); | ||
| assertEquals("Кошачьи", actualFamily); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аналогичное замечание. Нужно исправить |
||
|
|
||
| @Test | ||
| public void getFelineKittens() { | ||
| Feline feline = new Feline(); | ||
| int actualKittens = feline.getKittens(); | ||
| assertEquals(1, actualKittens); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аналогично. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нужно ещё раз разобраться, для чего используется параметризация. Чтобы протестировать метод, передав в него различные параметры. |
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import com.example.Feline; | ||
| import com.example.Lion; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| @RunWith(Parameterized.class) | ||
| public class LionParametrizedTest { | ||
|
|
||
| @Parameterized.Parameter | ||
| public int numberOfKittens; | ||
| @Mock | ||
| Feline feline; | ||
|
|
||
| @Parameterized.Parameters() | ||
| public static Object[][] getNumberOfKittens() { | ||
| return new Object[][]{ | ||
| {1}, | ||
| {2} | ||
| }; | ||
| } | ||
|
|
||
| @Before | ||
| public void init() { | ||
| MockitoAnnotations.initMocks(this); | ||
| } | ||
|
|
||
| @Test | ||
| public void getLionKittensTest() throws Exception { | ||
| Lion lion = new Lion("Самка", feline); | ||
| Mockito.when(feline.getKittens()).thenReturn(numberOfKittens); | ||
| Assert.assertEquals(numberOfKittens, lion.getKittens()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import com.example.Feline; | ||
| import com.example.Lion; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| import java.util.List; | ||
|
|
||
|
|
||
| public class LionTest { | ||
|
|
||
| @Mock | ||
| Feline feline; | ||
|
|
||
|
|
||
| @Before | ||
| public void init() { | ||
| MockitoAnnotations.initMocks(this); | ||
| } | ||
|
|
||
| @Test | ||
| public void getLionFoodTest() throws Exception { | ||
| Lion lion = new Lion("Самка", feline); | ||
| List<String> food = List.of("Животные", "Птицы", "Рыба"); | ||
| Mockito.when(feline.getFood("Хищник")).thenReturn(food); | ||
| Assert.assertEquals(food, lion.getFood()); | ||
| } | ||
|
|
||
| @Test | ||
| public void doesHaveManeMale() throws Exception { | ||
| Lion lion = new Lion("Самец", feline); | ||
| Assert.assertTrue(lion.doesHaveMane()); | ||
| } | ||
|
|
||
| @Test | ||
| public void doesHaveManeFemale() throws Exception { | ||
| Lion lion = new Lion("Самка", feline); | ||
| Assert.assertFalse(lion.doesHaveMane()); | ||
| } | ||
|
|
||
| @Test | ||
| public void doesHaveManeException() throws Exception { | ||
| Exception exception = Assert.assertThrows(Exception.class, () -> { | ||
| new Lion("Man", feline); | ||
| }); | ||
| Assert.assertEquals("Используйте допустимые значения пола животного - самец или самка", exception.getMessage()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отлично протестировано исключение! |
||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Каждый тест в этом классе повторится дважды, так как они находятся в параметризованном классе. Это нехорошо, нужно разнести по разным классам тесты, нуждающиеся в параметризации, и остальные. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| com\example\Predator.class | ||
| com\example\Animal.class | ||
| com\example\Cat.class | ||
| com\example\Lion.class | ||
| com\example\Feline.class |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| C:\projects\qa_java\src\main\java\com\example\Cat.java | ||
| C:\projects\qa_java\src\main\java\com\example\Feline.java | ||
| C:\projects\qa_java\src\main\java\com\example\Lion.java | ||
| C:\projects\qa_java\src\main\java\com\example\Animal.java | ||
| C:\projects\qa_java\src\main\java\com\example\Predator.java |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CatTest.class | ||
| LionTest.class | ||
| FelineTest.class |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| C:\projects\qa_java\src\test\java\CatTest.java | ||
| C:\projects\qa_java\src\test\java\FelineTest.java | ||
| C:\projects\qa_java\src\test\java\LionTest.java |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ru"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Animal</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">untitled</a> > <a href="index.html" class="el_package">com.example</a> > <span class="el_class">Animal</span></div><h1>Animal</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">11 of 27</td><td class="ctr2">59 %</td><td class="bar">2 of 4</td><td class="ctr2">50 %</td><td class="ctr1">3</td><td class="ctr2">5</td><td class="ctr1">3</td><td class="ctr2">7</td><td class="ctr1">1</td><td class="ctr2">3</td></tr></tfoot><tbody><tr><td id="a2"><a href="Animal.java.html#L8" class="el_method">getFood(String)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="49" height="10" title="9" alt="9"/><img src="../jacoco-resources/greenbar.gif" width="70" height="10" title="13" alt="13"/></td><td class="ctr2" id="c1">59 %</td><td class="bar" id="d0"><img src="../jacoco-resources/redbar.gif" width="60" height="10" title="2" alt="2"/><img src="../jacoco-resources/greenbar.gif" width="60" height="10" title="2" alt="2"/></td><td class="ctr2" id="e0">50 %</td><td class="ctr1" id="f0">2</td><td class="ctr2" id="g0">3</td><td class="ctr1" id="h0">2</td><td class="ctr2" id="i0">5</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="Animal.java.html#L18" class="el_method">getFamily()</a></td><td class="bar" id="b1"><img src="../jacoco-resources/redbar.gif" width="10" height="10" title="2" alt="2"/></td><td class="ctr2" id="c2">0 %</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">1</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">1</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a0"><a href="Animal.java.html#L5" class="el_method">Animal()</a></td><td class="bar" id="b2"><img src="../jacoco-resources/greenbar.gif" width="16" height="10" title="3" alt="3"/></td><td class="ctr2" id="c0">100 %</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f2">0</td><td class="ctr2" id="g2">1</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i2">1</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k2">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ru"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Animal.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">untitled</a> > <a href="index.source.html" class="el_package">com.example</a> > <span class="el_source">Animal.java</span></div><h1>Animal.java</h1><pre class="source lang-java linenums">package com.example; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| <span class="fc" id="L5">public class Animal {</span> | ||
|
|
||
| public List<String> getFood(String animalKind) throws Exception { | ||
| <span class="pc bpc" id="L8" title="1 of 2 branches missed."> if ("Травоядное".equals(animalKind)) {</span> | ||
| <span class="nc" id="L9"> return List.of("Трава", "Различные растения");</span> | ||
| <span class="pc bpc" id="L10" title="1 of 2 branches missed."> } else if ("Хищник".equals(animalKind)) {</span> | ||
| <span class="fc" id="L11"> return List.of("Животные", "Птицы", "Рыба");</span> | ||
| } else { | ||
| <span class="nc" id="L13"> throw new Exception("Неизвестный вид животного, используйте значение Травоядное или Хищник");</span> | ||
| } | ||
| } | ||
|
|
||
| public String getFamily() { | ||
| <span class="nc" id="L18"> return "Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи";</span> | ||
| } | ||
| } | ||
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ru"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Cat</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">untitled</a> > <a href="index.html" class="el_package">com.example</a> > <span class="el_class">Cat</span></div><h1>Cat</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 16</td><td class="ctr2">100 %</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">3</td><td class="ctr1">0</td><td class="ctr2">6</td><td class="ctr1">0</td><td class="ctr2">3</td></tr></tfoot><tbody><tr><td id="a0"><a href="Cat.java.html#L9" class="el_method">Cat(Feline)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="9" alt="9"/></td><td class="ctr2" id="c0">100 %</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">4</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="Cat.java.html#L19" class="el_method">getFood()</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="53" height="10" title="4" alt="4"/></td><td class="ctr2" id="c1">100 %</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a2"><a href="Cat.java.html#L15" class="el_method">getSound()</a></td><td class="bar" id="b2"><img src="../jacoco-resources/greenbar.gif" width="40" height="10" title="3" alt="3"/></td><td class="ctr2" id="c2">100 %</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f2">0</td><td class="ctr2" id="g2">1</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i2">1</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k2">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Файлы .idea коммитить не нужно . Нужно добавить их в gitignore. Нужно исправить