-
Notifications
You must be signed in to change notification settings - Fork 57
Медведев Фома, ДЗ по тестированию #44
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: master
Are you sure you want to change the base?
Changes from all commits
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,4 +1,5 @@ | ||
| using NUnit.Framework; | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Legacy; | ||
|
|
||
| namespace HomeExercise.Tasks.ObjectComparison; | ||
|
|
@@ -10,31 +11,28 @@ public class ObjectComparison | |
| public void CheckCurrentTsar() | ||
| { | ||
| var actualTsar = TsarRegistry.GetCurrentTsar(); | ||
|
|
||
| var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, | ||
| new Person("Vasili III of Russia", 28, 170, 60, null)); | ||
|
|
||
| // Перепишите код на использование Fluent Assertions. | ||
| ClassicAssert.AreEqual(actualTsar.Name, expectedTsar.Name); | ||
| ClassicAssert.AreEqual(actualTsar.Age, expectedTsar.Age); | ||
| ClassicAssert.AreEqual(actualTsar.Height, expectedTsar.Height); | ||
| ClassicAssert.AreEqual(actualTsar.Weight, expectedTsar.Weight); | ||
|
|
||
| ClassicAssert.AreEqual(expectedTsar.Parent!.Name, actualTsar.Parent!.Name); | ||
| ClassicAssert.AreEqual(expectedTsar.Parent.Age, actualTsar.Parent.Age); | ||
| ClassicAssert.AreEqual(expectedTsar.Parent.Height, actualTsar.Parent.Height); | ||
| ClassicAssert.AreEqual(expectedTsar.Parent.Parent, actualTsar.Parent.Parent); | ||
| var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, 99999999, | ||
| new Person("Vasili III of Russia", 28, 170, 60, 99999999, null)); | ||
|
|
||
| actualTsar.Should() | ||
| .BeEquivalentTo(expectedTsar, | ||
| config => config | ||
| .Excluding(person => person.Id) | ||
| .Excluding(person => person.Parent.Id)); | ||
| // Я специально для теста добавил одно поле, а сам тест остался неизменен. По сути, его нужно изменять только в случае, если нужно добавить какое-то поле в игнор | ||
| // типа того, как я добавил айдишники людей, т. е. там скорее всего окажутся только поля, которые должны быть уникальными для каждого объекта, а таких вряд ли будет прям много | ||
| } | ||
|
|
||
| [Test] | ||
| [Description("Альтернативное решение. Какие у него недостатки?")] | ||
| public void CheckCurrentTsar_WithCustomEquality() | ||
| { | ||
| var actualTsar = TsarRegistry.GetCurrentTsar(); | ||
| var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, | ||
| new Person("Vasili III of Russia", 28, 170, 60, null)); | ||
| var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, 99999999, | ||
| new Person("Vasili III of Russia", 28, 170, 60, 99999999, null)); | ||
|
|
||
| // Какие недостатки у такого подхода? | ||
| // Этот код более читаем, чем был изначальный вариант в первом тесте, но его необходимо будет изменять каждый раз, когда мы будем менять класс, который тестируем | ||
|
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. Давай ещё раз проведём сравнение и аккуратно, но развернуто распишем (оставь комментарий здесь или в коде):
Author
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.
|
||
| ClassicAssert.True(AreEqual(actualTsar, expectedTsar)); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
|
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. Расскажи, что это за правки и зачем они нужны в рамках данной задачи?) |
||
| <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADefaultTestCaseBuilder_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FSourcesCache_003F40cbefd211328d0387117e65923cdf13595b5e0e21e2068a421a51011b5a_003FDefaultTestCaseBuilder_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> | ||
| <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATestCaseSourceAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fcd60bd81539a9932fef279e34bb8da2acbbedd179a22dd9859da7cf7279f15b4_003FTestCaseSourceAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> | ||
| <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=03d02b35_002D3e85_002D48cc_002D9209_002D8b64406a4fae/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="NumberValidatorTests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
| <TestAncestor>
 | ||
| <TestId>NUnit3x::6ED454CB-A772-43E5-B72D-3FE9DA27337F::net8.0::HomeExercise.Tasks.NumberValidator.NumberValidatorTests</TestId>
 | ||
| </TestAncestor>
 | ||
| </SessionState></s:String></wpf:ResourceDictionary> | ||
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.
На будущее отмечу: в рамках учебных заданий это ОК, но в реальных проектах комментарии, адресованные ревьюеру, обычно оставляют в github/gitlab и т.д.
Uh oh!
There was an error while loading. Please reload this page.
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.
А как следует оставлять комментарии в github? В pull request их добавлять, или как-то иначе?
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.
В pull request. При этом оставлять поясняющие комментарии в коде - это нормальная практика, если ты хочешь, чтобы этот комментарий остался в коде "навсегда" и предназначался для всех разработчиков, с которыми ты работаешь над одним кодом. В нашем же случае ты оставлял комментарий для наставника - просто, чтобы я его увидел и имел ввиду. Такое лучше не оставлять в коде, а выносить в pull request (или merge request в случае с gitlab, с которым если ещё не сталкивался, то обязательно столкнешься)