성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] 정적 분석과 함께, 이제는 실행 시 성능 분석까지 (비록 Azu...
[정성태] .NET Source Browser를 이용해 Roslyn 소스 ...
[정성태] Experimental C# Interceptors: AOT &...
[정성태] .NET Conf 2023 (Day 2) - Tiny, fast...
[정성태] The end of the Tye Experiment #1622...
[정성태] This is a simple app that converts ...
[정성태] Wrathmark: An Interesting Compute W...
[정성태] FFmpeg Filters Every Youtuber Needs...
[정성태] 일단, PInvokeStackImbalance 오류가 발생했다는...
[Heegyoo Lee] 코드 자체는 동작하는 것처럼 보이는데요. (어떤 때는 시그니쳐가...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C# 단위 테스트 - MSTestv2/NUnit의 Assert.Inconclusive 사용법(?)</h1> <p> <a target='tab' href='https://www.sysnet.pe.kr/2/0/12726'>MSTestv2/NUnit</a>의 경우 Assert 타입이 제공하는 많은 static 메서드 중에 Inconclusive의 사용법이 모호합니다. 검색해 보면 아래와 같은 식의 Q&A가 있는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Usage of Assert.Inconclusive ; <a target='tab' href='https://stackoverflow.com/questions/1219274/usage-of-assert-inconclusive'>https://stackoverflow.com/questions/1219274/usage-of-assert-inconclusive</a> </pre> <br /> 사실 단어가 좀 낯설어서 그렇지 "결정되지 않은, 확정이 안 된"이라는 단어 뜻 그대로 받아들이면 됩니다. ^^; 그렇다면 실 사용예로 어떤 경우가 있을까요? 사실 이런 경우를 찾기가 쉽지 않은데, 왜냐하면 해당 assertion을 제공하는 마이크로소프트조차도 초기의 의지와는 달리 Inconclusive로 개발자들이 혼란스러워 하는 모습을 짐작이라도 하듯 이후에는 사용하지 않고 있기 때문입니다.<br /> <br /> 실제로 아래의 그림을 보면,<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='assert_inclusive_1.png' src='/SysWebRes/bbs/assert_inclusive_1.png' /><br /> <br /> 왼쪽은 Visual Studio 2005 Team System의 "Test Generation Settings" 대화창 화면인데, 옵션에서 보듯이 "Mark all test results Inconclusive by default"가 기본 선택돼 있지만 오른쪽 화면의 현재 Visual Studio 2019에서는 Inconclusive 옵션을 선택할 수 있는 방법이 없습니다. (웹을 검색해 보면 "Mark all test results Inconclusive by default" 옵션이 <a target='tab' href='https://www.c-sharpcorner.com/uploadfile/sanks/visual-studio-2010-tools-to-improve-code-quality/'>Visual Studio 2010까지는 있었던 것</a> 같습니다.)<br /> <br /> 어쨌든, 이제는 다음과 같이 개발자가 명시적으로 호출을 해야만 하는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > [TestMethod()] public void AddTest() { <span style='color: blue; font-weight: bold'>Assert.Inconclusive();</span> } </pre> <br /> 이렇게 하고 단위 테스트를 수행하면 다음과 같은 결과를 볼 수 있습니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='assert_inclusive_2.png' src='/SysWebRes/bbs/assert_inclusive_2.png' /><br /> <br /> 보는 바와 같이 루트 노드의 테스트는 성공이라는 의미를 담고 있지만, 정작 AddTest에 한해서는 (성공도, 실패도 아닌) 느낌표로 보여주는 것이 전부입니다. 원래의 마이크로소프트의 의도라면 초기에 개발자가 아직 단위 테스트 코드를 완료하지 않았거나, 아니면 단위 테스트를 수행할 대상 메서드의 구현이 아직 완료되지 않은 시점에 미리 "관심이 필요하다"는 식의 assertion 용도였을 것입니다. 반면 <a target='tab' href='https://docs.nunit.org/articles/nunit/writing-tests/assertions/classic-assertions/Assert.Inconclusive.html'>NUnit의 문서</a>에 따르면 테스트 관련 데이터의 차이에 따라 성공/실패가 달라지면 사용할 수 있다는데... 사실 그런 경우는 그냥 Fail에 가까운 경우가 더 많을 것입니다.<br /> <br /> 참고로, Ignore 특성도 유사한 결과를 냅니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > [TestMethod()] <span style='color: blue; font-weight: bold'>[Ignore]</span> public void AddTest() { // ...[생략]... } </pre> <br /> 이것 역시 단위 테스트 수행 시 결과는 위의 Inconclusive와 마찬가지로 "느낌표" 아이콘을 보여줍니다. 하지만, Inconclusive와는 다르게 AddTest 내의 코드를 전혀 실행하지 않는다는 차이점이 있습니다.<br /> <br /> 따라서, "관심이 필요하다" 정도의 표시를 하는 다양하고 직관적인 다른 방법들이 있기 때문에 Inconclusive는 이제 거의 쓰이지 않는 assertion 유형이 될 듯합니다. (혹시 Inconclusive만의 독보적인 사례가 있다면 덧글 부탁드립니다. ^^)<br /> <br /> <hr style='width: 50%' /> <br /> 참고로, MSTest에서 지원하는 Assert 관련 클래스와 메서드는 다음과 같은 것들이 있습니다. (이름만 봐도 용도를 알 수 있을 것입니다. ^^)<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Assert AreEqual AreNotEqua AreSame AreNotSame IsTrue IsFalse IsNull IsNotNull IsInstanceOfType IsNotInstanceOfType Fail Inconclusive CollectionAssert AllItemsAreInstancesOfType AllItemsAreNotNull AllItemsAreUnique AreEqual AreNotEqual AreEquivalent AreNotEquivalent Contains DoesNotContain IsNotSubsetOf IsSubsetOf StringAssert Contains DoesNotMatch EndsWith Matches StartsWith </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1511
(왼쪽의 숫자를 입력해야 합니다.)