<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>XP Practices - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/category/xp-practices/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Tue, 24 Nov 2026 15:39:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>XP Practices - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to use Visual Studio Live Share &#8211; Paired Programming and Collaboration</title>
		<link>https://thecodebuzz.com/visual-studio-live-share-getting-started/</link>
					<comments>https://thecodebuzz.com/visual-studio-live-share-getting-started/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 01 Mar 2022 00:00:00 +0000</pubDate>
				<category><![CDATA[XP Practices]]></category>
		<category><![CDATA[how to use live share]]></category>
		<category><![CDATA[live share download]]></category>
		<category><![CDATA[live share vscode not working]]></category>
		<category><![CDATA[Live Share-Collaborate using Visual Studio Code]]></category>
		<category><![CDATA[visual studio live share audio]]></category>
		<category><![CDATA[vscode live share github]]></category>
		<category><![CDATA[vscode live share security]]></category>
		<category><![CDATA[vscode live share server]]></category>
		<category><![CDATA[vscode live share source code]]></category>
		<guid isPermaLink="false">https://thecodebuzz.com/?p=3033</guid>

					<description><![CDATA[<p>How to use Visual Studio Live Share -Paired Programming and Collaboration Today in this article, we shall see Visual Studio Live Share features in detail. Recently I happened to try and use Live Share and was stunned by the power of this tool. If I ever opt to choose the best feature or tools recently [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/visual-studio-live-share-getting-started/">How to use Visual Studio Live Share – Paired Programming and Collaboration</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">How to use Visual Studio Live Share -Paired Programming and Collaboration</h1>



<figure class="is-resized wp-block-image"><a href="https://www.thecodebuzz.com/visual-studio-live-share-getting-started/" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" width="1177" height="578" src="https://i2.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/image-32.jpg?fit=785%2C386&amp;ssl=1" alt="Paired Programming using liveshare" class="wp-image-3116" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/image-32.jpg 1177w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-32-300x147.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-32-1024x503.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-32-768x377.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-32-785x385.jpg 785w" sizes="(max-width: 1177px) 100vw, 1177px" /></a></figure>



<p class="wp-block-paragraph">Today in this article, we shall see Visual Studio Live Share features in detail.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Recently I happened to try and use Live Share and was stunned by the power of this tool. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">If I ever opt to choose the best feature or tools recently released by Microsoft, then Live Share would be my first choice undoubtedly.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Visual Studio Live Share certainly aims to do away with the traditional practice of sharing the screen via Skype, Slack, or Teams instead of the live interactive code-sharing session. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">One can share a file or full project context with continuous collaboration bringing Developers, Testers, and Architects together. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">This is one of the tools that can take <strong>SDLC </strong>to the next level as software industries are leaning towards more lean-agile and <strong>T-shaped</strong> teams. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">As we are now aware the primary goal of<strong> Live Share</strong> is to enable developers to collaborate easily. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">There are below additional use cases that Live Share is capable of addressing.</p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class=""><strong>Paired programming</strong></li>



<li class=""><strong>Continuous Code Review</strong></li>



<li class=""><strong>Interactive Learning/Session</strong></li>



<li class=""><strong>Technical Interviews</strong></li>



<li class=""><strong>+ Many more </strong></li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Let&#8217;s get started and follow the step-by-step process to configure live share for Visual Studio Code.</p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-prerequisites">Prerequisites</a></li><li><a href="#aioseo-getting-started">Getting Started &#8211; Visual Studio Live Share</a><ul><li><a href="#aioseo-install-visual-studio-code-live-share">Install Visual Studio Code Live Share</a></li></ul></li><li><a href="#aioseo-sharing-project-or-files">Sharing Project or Files</a></li><li><a href="#aioseo-real-time-collaboration-in-vscode-and-vs2019">Real-time Collaboration in VSCode and VS2019</a></li><li><a href="#aioseo-stopping-the-collaboration-session">Stopping the collaboration session</a></li><li><a href="#aioseo-sharing-terminal-windows">Sharing Terminal windows &#8211; Visual Studio Live Share</a></li><li><a href="#aioseo-collaborative-debugging">Collaborative Debugging &#8211; Visual Studio Live Share</a></li><li><a href="#aioseo-highlights">Highlights of Visual Studio Live Share</a></li><li><a href="#aioseo-summary">Summary</a></li></ul></div>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-prerequisites"><strong>Prerequisites</strong></h2>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class=""><strong>IDE &#8211; Visual Studio Code</strong> (1.22 or higher) , <strong>VS2017</strong>(15.6 and above) or <strong>VS2019</strong></li>



<li class=""><strong>OS </strong>&#8211; <strong>Windows </strong>(7,8 or 10) , <strong>macOS</strong>(10.12) , <strong>Linux </strong>(Ubuntu 16.04+, Fedora 27+,CenterOS7)</li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-getting-started">Getting Started &#8211; Visual Studio Live Share</h2>



<p class="wp-block-paragraph"></p>



<h4 class="wp-block-heading" id="aioseo-install-visual-studio-code-live-share"><strong>Install Visual Studio Code Live Share</strong></h4>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Install through VS extension within VS Code.</li>
</ul>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img decoding="async" width="1760" height="479" src="https://i1.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-extension.jpg?fit=785%2C214&amp;ssl=1" alt="Paired Programming" class="wp-image-3066" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-extension.jpg 1760w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-extension-300x82.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-extension-1024x279.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-extension-768x209.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-extension-1536x418.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-extension-785x214.jpg 785w" sizes="(max-width: 1760px) 100vw, 1760px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">OR Please install from <a href="https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare-pack">Market place</a> </p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Once installed successfully Live share icon can be seen in the Status Bar and Activity Bar. Please open the project or files to use it for Live share,</li>
</ul>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img decoding="async" width="924" height="1185" src="https://i2.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-1.jpg?fit=785%2C1007&amp;ssl=1" alt="Visual Studio Live Share in Visual studio code" class="wp-image-3069" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-1.jpg 924w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-1-234x300.jpg 234w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-1-798x1024.jpg 798w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-1-768x985.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-1-405x520.jpg 405w" sizes="(max-width: 924px) 100vw, 924px" /></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-sharing-project-or-files">Sharing Project or Files</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Please click on Live Share in the Status Bar or Activity as shown above. </p>



<p class="wp-block-paragraph">Users will be prompted with the below information message showing the default connection mode used will be &#8220;Auto&#8221;. Please click &#8220;OK&#8221; to proceed.</p>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img loading="lazy" decoding="async" width="1722" height="566" src="https://i1.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/image-26.png?fit=785%2C258&amp;ssl=1" alt="Activate Visual Studio Live Share" class="wp-image-3073" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/image-26.png 1722w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-26-300x99.png 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-26-1024x337.png 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-26-768x252.png 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-26-1536x505.png 1536w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-26-785x258.png 785w" sizes="auto, (max-width: 1722px) 100vw, 1722px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">An invite link will be copied to your clipboard automatically. </p>



<p class="wp-block-paragraph">Once you start your collaboration session, you can set the session to be read-only to prevent guests from making edits. </p>



<p class="wp-block-paragraph">By default, it will be read-write mode will be enabled the user will be able to edit the code shared in the session.</p>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img loading="lazy" decoding="async" width="2320" height="739" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/image-27.png?fit=785%2C250&amp;ssl=1" alt="Visual Studio Live Share in Visual studio code" class="wp-image-3075" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/image-27.png 2320w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-27-300x96.png 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-27-1024x326.png 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-27-768x245.png 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-27-1536x489.png 1536w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-27-2048x652.png 2048w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-27-785x250.png 785w" sizes="auto, (max-width: 2320px) 100vw, 2320px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Let&#8217;s share this link with someone who wants to collaborate. I tried sharing this link to someone who has Visual Studio 2017 or 2019 installed but not VS Code. I found it to be working perfectly fine.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Participants joining the shared link need to click on<strong> &#8216;Join collaboration sessions.</strong></p>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img loading="lazy" decoding="async" width="1446" height="812" src="https://i1.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session.jpg?fit=785%2C441&amp;ssl=1" alt="" class="wp-image-3080" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session.jpg 1446w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-300x168.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-1024x575.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-768x431.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-785x441.jpg 785w" sizes="auto, (max-width: 1446px) 100vw, 1446px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Participants enter the invite link within the command pallet windows below</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="2267" height="262" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2.jpg?fit=785%2C90&amp;ssl=1" alt="" class="wp-image-3079" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2.jpg 2267w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2-300x35.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2-1024x118.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2-768x89.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2-1536x178.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2-2048x237.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session2-785x91.jpg 785w" sizes="auto, (max-width: 2267px) 100vw, 2267px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Once connected all participants will be visible under the session details as below,</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="2026" height="767" src="https://i1.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-joined.jpg?fit=785%2C297&amp;ssl=1" alt="Share screen using Live share" class="wp-image-3081" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-joined.jpg 2026w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-joined-300x114.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-joined-1024x388.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-joined-768x291.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-joined-1536x581.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-joined-785x297.jpg 785w" sizes="auto, (max-width: 2026px) 100vw, 2026px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Let’s allow 1 more new participant (with VS2019) to collaborate. </p>



<p class="wp-block-paragraph">Please note that the collaboration between the VSCode and VS2019 works perfectly fine.</p>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img loading="lazy" decoding="async" width="643" height="902" src="https://www.thecodebuzz.com/wp-content/uploads/2019/05/image-29.png" alt="Live session with Live share" class="wp-image-3093" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/image-29.png 643w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-29-214x300.png 214w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-29-371x520.png 371w" sizes="auto, (max-width: 643px) 100vw, 643px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Participants joining the same meeting invite using <strong>VS2019</strong>.</p>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img loading="lazy" decoding="async" width="1617" height="884" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/image-30.png?fit=785%2C429&amp;ssl=1" alt="" class="wp-image-3094" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/image-30.png 1617w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-30-300x164.png 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-30-1024x560.png 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-30-768x420.png 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-30-1536x840.png 1536w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-30-785x429.png 785w" sizes="auto, (max-width: 1617px) 100vw, 1617px" /></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-real-time-collaboration-in-vscode-and-vs2019">Real-time Collaboration in VSCode and VS2019  </h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">The below figure shows the real-time Live Share Collaboration in VSCode and VS2019 for the shared codebase.</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="700" height="372" src="https://www.thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-join-session-gif.gif" alt="Visual Studio Live Share in Visual studio code" class="wp-image-3096"/><figcaption class="wp-element-caption">Live Share collaboration in <strong>VSCode </strong>and <strong>VS2019 </strong></figcaption></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-stopping-the-collaboration-session">Stopping the collaboration session</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"> Stopping the sharing session can be done using the below options,</p>



<p class="wp-block-paragraph"></p>



<figure class="is-resized wp-block-image"><img loading="lazy" decoding="async" width="1107" height="782" src="https://i2.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/image-31.jpg?fit=785%2C554&amp;ssl=1" alt="" class="wp-image-3099" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/image-31.jpg 1107w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-31-300x212.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-31-1024x723.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-31-768x543.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/image-31-736x520.jpg 736w" sizes="auto, (max-width: 1107px) 100vw, 1107px" /></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-sharing-terminal-windows">Sharing Terminal windows &#8211; Visual Studio Live Share</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Apart from sharing projects or files, Live Share allows you to share your terminal window with other users. The shared terminal can be read-only (default) or read/write thereby allowing full collaboration. </p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1236" height="800" src="https://i2.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-share-terminal.jpg?fit=785%2C508&amp;ssl=1" alt="" class="wp-image-3105" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-share-terminal.jpg 1236w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-share-terminal-300x194.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-share-terminal-1024x663.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-share-terminal-768x497.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/VSLive-share-icon-vscode-share-terminal-785x508.jpg 785w" sizes="auto, (max-width: 1236px) 100vw, 1236px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Each participant can run commands on the terminal window, see the results, do Builds, run test cases. </p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://www.thecodebuzz.com/wp-content/uploads/2021/11/vscode-live-share-debugging-terminal-window-GIF-1024x576.gif" alt="" class="wp-image-19241" srcset="https://thecodebuzz.com/wp-content/uploads/2021/11/vscode-live-share-debugging-terminal-window-GIF-1024x576.gif 1024w, https://thecodebuzz.com/wp-content/uploads/2021/11/vscode-live-share-debugging-terminal-window-GIF-300x169.gif 300w, https://thecodebuzz.com/wp-content/uploads/2021/11/vscode-live-share-debugging-terminal-window-GIF-768x432.gif 768w, https://thecodebuzz.com/wp-content/uploads/2021/11/vscode-live-share-debugging-terminal-window-GIF-1536x864.gif 1536w, https://thecodebuzz.com/wp-content/uploads/2021/11/vscode-live-share-debugging-terminal-window-GIF-785x442.gif 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="aioseo-collaborative-debugging"><br>Collaborative Debugging &#8211; Visual Studio Live Share</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Visual Studio Live Share allows a team to follow a collaborative debugging technique to solve any problem/issue. Team members can use this technique for troubleshooting issues by providing a shared debugging session on the host&#8217;s machine.</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1897" height="924" src="https://i2.wp.com/thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-debugging.jpg?fit=785%2C383&amp;ssl=1" alt="" class="wp-image-3111" srcset="https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-debugging.jpg 1897w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-debugging-300x146.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-debugging-1024x499.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-debugging-768x374.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-debugging-1536x748.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2019/05/vscode-live-share-debugging-785x382.jpg 785w" sizes="auto, (max-width: 1897px) 100vw, 1897px" /></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-highlights">Highlights of Visual Studio Live Share</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Here I have listed a few nice-to-know characteristics of Live Share for your information,</p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Visual Studio Live Share is <strong>SSH or SSL </strong>encrypted and authenticated.</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Live Share allows a user to share the Terminal window with each other. </li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Users can perform remote debugging by sharing the locally hosted server application.</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Live Share allows you to share your active debug session, without requiring participants to install any of the necessary platforms <strong>SDKs (e.g. Node.js, Go, .NET Core)</strong> or tooling extensions.</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Live Share allows you to share debug state for any programming language or runtime environment (e.g. Kubernetes, React Native app)</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Live Share allows you to share code between different <strong>IDE </strong>like <strong>VSCode </strong>and <strong>Visual </strong>Studio is possible. </li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Embedded JavaScript in HTML is supported when doing client debugging.</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">JavaScript / TypeScript debugging for Node or browser is supported.</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Currently, the guest limit is up to 30 users. (Please check for any updates on limits)</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Users can join in read-only mode to avoid accidental edits.</li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class="">Live Share allows you to control sensitive file access and visibility if required.</li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong><em>References</em></strong>:</p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li class=""><a href="https://www.thecodebuzz.com/visual-studio-intellicode-code-development-using-ai/" target="_blank" rel="noopener" title="Visual Studio IntelliCode –  Code Development using AI"><strong><em>Visual Studio IntelliCode –  Code Development using AI</em></strong></a></li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph" style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size wp-block-paragraph"></p>



<p class="wp-block-paragraph" style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size wp-block-paragraph"></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>Happy Coding </strong>!!</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-summary"><strong>Summary</strong></h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong><em>VS Live Share</em></strong> is undoubtedly one of the most recent features from Microsoft. Live share enables developers to collaborate easily and also eases performing extreme programming(XP) practices like paired programming, mob programming, continuous code review, performing Interactive Learnings, conducting brainstorming Sessions, etc&#8230;</p>



<hr>



<p class="wp-block-paragraph"></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"> </p><p>The post <a href="https://thecodebuzz.com/visual-studio-live-share-getting-started/">How to use Visual Studio Live Share – Paired Programming and Collaboration</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/visual-studio-live-share-getting-started/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Unit Test and Mock ActionFilter in ASP.NET Core</title>
		<link>https://thecodebuzz.com/unit-test-mock-actionfilter-asp-net-core-actionexecutingcontext-moq/</link>
					<comments>https://thecodebuzz.com/unit-test-mock-actionfilter-asp-net-core-actionexecutingcontext-moq/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 19 Dec 2021 02:16:00 +0000</pubDate>
				<category><![CDATA[XP Practices]]></category>
		<category><![CDATA[.net core unit test mock]]></category>
		<category><![CDATA[asp net core unit test authorization]]></category>
		<category><![CDATA[asp net core unit test dependency injection]]></category>
		<category><![CDATA[asp net core unit testing]]></category>
		<category><![CDATA[asp net core web api unit testing example]]></category>
		<category><![CDATA[resultexecutingcontext unit test]]></category>
		<category><![CDATA[unit test actionfilterattribute]]></category>
		<category><![CDATA[unit testing in asp net]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=19667</guid>

					<description><![CDATA[<p>Unit Test and Mock ActionFilter and ActionExecutingContext Today in this article we shall see how to Unit Test and Mock ActionFilter and mock ActionExecutingContext classes often useful for testing the controller logic in the API or ASP.NET Core MVC application. You can use the below-discussed approach using the XUnit or NUnit or MSTest framework of [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/unit-test-mock-actionfilter-asp-net-core-actionexecutingcontext-moq/">Unit Test and Mock ActionFilter in ASP.NET Core</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Unit Test and Mock ActionFilter and ActionExecutingContext</h1>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="394" src="https://www.thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-1024x394.jpg" alt="Unit Test and Mock ActionFilter " class="wp-image-19669" style="width:611px;height:235px" srcset="https://thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-1024x394.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-300x115.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-768x296.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-785x302.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter.jpg 1351w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Today in this article we shall see how to Unit Test and Mock ActionFilter and mock ActionExecutingContext classes often useful for testing the controller logic in the API or ASP.NET Core MVC application.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">You can use the below-discussed approach using the XUnit or NUnit or MSTest framework of your choice.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Unit <a href="https://www.thecodebuzz.com/moq-to-mock-asynchronous-method-net-core-unit-tests/">test cases of controller-specific methods</a> make API robust and help identify any breaking changes early.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">We shall use below sample code below where the controller is attributed with filter attribute i.e <strong><em>ApiInputInterceptor </em></strong>attribute as shown below example,</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="736" height="166" src="https://www.thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-Controller-ASp.NET-Core-1.jpg" alt="Mock OnActionExecuting and ActionFilter" class="wp-image-19671" srcset="https://thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-Controller-ASp.NET-Core-1.jpg 736w, https://thecodebuzz.com/wp-content/uploads/2021/12/Unit-Test-and-Mock-Action-filter-Controller-ASp.NET-Core-1-300x68.jpg 300w" sizes="auto, (max-width: 736px) 100vw, 736px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">The controller with action filters includes the below-listed methods. These methods wrap the filters that run for a given action,</p>



<p class="wp-block-paragraph"></p>



<ul class="has-medium-font-size wp-block-list">
<li><code>OnActionExecuting</code> &#8211; runs before any of the action&#8217;s filters.</li>



<li><a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controller.onactionexecuted?view=aspnetcore-6.0" target="_blank" rel="noreferrer noopener"><code>OnActionExecuted</code> </a>&#8211; runs after all of the action&#8217;s filters.</li>



<li>Or <code>OnActionExecutionAsync</code>&#8211; async format </li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Below is the simplified implementation of the ApiInputInterceptor for demonstration purposes,</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<pre class="wp-block-code"><code>public class ApiInputInterceptor : ActionFilterAttribute,IActionFilter
    {
   
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            // do something before
            if (!context.ActionArguments.ContainsKey("Id"))
            {
                context.Result = new BadRequestObjectResult("The id must be passed as parameter");
                return;
            }
        }
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            //throw new NotImplementedException();
        }
    }</code></pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Let&#8217;s now create the Unit test case for this <em>Action filter</em> attribute which is of type ApiInputInterceptor</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Step 1- Create Mock of ActionContext</strong></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Below is a simple way of creating a mock of ActionContext. This mock object will be needed in the next steps where we will create a mock setup for <strong><em>ActionExecutingContext</em></strong>.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Below we are creating a mock object of  HttpContext,  RouteData, and  ActionDescriptor using the <strong>moq </strong>library.</p>



<p class="wp-block-paragraph"></p>



<pre class="wp-block-preformatted has-medium-font-size"> var actContext = new ActionContext(
                Mock.Of&lt;HttpContext&gt;(),
                Mock.Of&lt;RouteData&gt;(),
                Mock.Of&lt;ActionDescriptor&gt;(),
                Mock.Of&lt;ModelStateDictionary&gt;()
            );</pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Step 2- Create Mock of ActionExecutingContext</strong></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Let&#8217;s now create the mock for <strong>ActionExecutingContext </strong>using the mock action context object as defined above. We are also passing a mock list of IFilterMetadata and Dictionary key-value pairs.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<pre class="wp-block-preformatted has-medium-font-size">var actExecutingContext = new ActionExecutingContext(
                actionContext,
                new List&lt;IFilterMetadata&gt;(),
                new Dictionary&lt;string, object&gt;(),
                Mock.Of&lt;Controller&gt;()
            );</pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Step 3: Define action arguments </strong>for GET or POST method</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">If input arguments expect an input with the name &#8220;id&#8221; then please define it as below,</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong><em>Example </em></strong></p>



<p class="wp-block-paragraph"></p>



<pre class="wp-block-preformatted has-medium-font-size"> actionExecutingContext.ActionArguments["Id"] = "123";
</pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">If action arguments expect a <strong><em>complex type </em></strong>as arguments especially in case POST operation then below is a sample example on defining the complex or class object as an action argument.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong><em>Example</em></strong></p>



<p class="wp-block-paragraph"></p>



<pre class="wp-block-preformatted has-medium-font-size">var source = new Source
            {
                FirstName = "ABCD",
                Address = "USA",
                Id = "1232"
            };
actionExecutingContext.ActionArguments["Id"] = source;
</pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Let&#8217;s define the action by creating the instance of <strong><em>ValidateInputAttribute </em></strong>and executing the <em><strong>OnActionExecuting </strong></em>method</p>



<p class="wp-block-paragraph"></p>



<pre class="wp-block-preformatted has-medium-font-size"> //Act

  var valInputObject = new ApiInputInterceptor();
  valInputObject.OnActionExecuting(actionExecutingContext);</pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Step 4: Define Assert</strong></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">We are making sure the result of validation fails reports <strong><em>BadRequestObjectResult </em></strong>as shown below,</p>



<p class="wp-block-paragraph"></p>



<pre class="wp-block-preformatted has-medium-font-size">Assert.IsType&lt;BadRequestObjectResult&gt;(actionExecutingContext.Result);

</pre>



<p class="wp-block-paragraph"><strong>Useful References </strong></p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/restful-api-controller-unit-testing-best-practices/" target="_blank" rel="noreferrer noopener" title="RESTFul API/Controller Unit Testing – Best Practices"><strong><em>RESTFul API/Controller Unit Testing – Best Practices</em></strong></a></li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph" style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size wp-block-paragraph"></p>



<p class="wp-block-paragraph" style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size wp-block-paragraph"></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>Happy Coding </strong>!!</p>



<p class="wp-block-paragraph"></p>



<hr>



<p class="wp-block-paragraph"></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p><p>The post <a href="https://thecodebuzz.com/unit-test-mock-actionfilter-asp-net-core-actionexecutingcontext-moq/">Unit Test and Mock ActionFilter in ASP.NET Core</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/unit-test-mock-actionfilter-asp-net-core-actionexecutingcontext-moq/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Unit Test Naming Conventions Best Practices</title>
		<link>https://thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/</link>
					<comments>https://thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 15 Dec 2021 23:49:00 +0000</pubDate>
				<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[XP Practices]]></category>
		<category><![CDATA[Define naming for Test Class]]></category>
		<category><![CDATA[Define naming for Test Files]]></category>
		<category><![CDATA[integration test naming convention]]></category>
		<category><![CDATA[jest unit test naming convention]]></category>
		<category><![CDATA[manual test case naming convention]]></category>
		<category><![CDATA[name test method]]></category>
		<category><![CDATA[Naming Conventions for Test method]]></category>
		<category><![CDATA[naming test method]]></category>
		<category><![CDATA[test case naming conventions best practices]]></category>
		<category><![CDATA[unit test best practices]]></category>
		<category><![CDATA[unit test naming convention c#]]></category>
		<category><![CDATA[unit test naming convention given when then]]></category>
		<category><![CDATA[unit test naming convention python]]></category>
		<category><![CDATA[Unit Testing Naming Conventions and Standards Tests]]></category>
		<category><![CDATA[use AAA pattern unit test]]></category>
		<category><![CDATA[use given when given pattern test cases.]]></category>
		<category><![CDATA[xunit name test method]]></category>
		<guid isPermaLink="false">https://thecodebuzz.com/?p=6698</guid>

					<description><![CDATA[<p>TDD &#8211; Unit Test Naming Conventions Best Practices I’m going to talk about simple and easy-to-understand Unit Test Naming Conventions and Best Practices that can be followed while writing Unit Testing. As we know Naming standards in any format for anything ( code, documents, unit tests, etc) are always helpful in the long run. The [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/">Unit Test Naming Conventions Best Practices</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>TDD &#8211; Unit Test Naming Conventions Best Practices</strong></h1>



<figure class="wp-block-image"><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noopener"><img decoding="async" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/01/Unit-Testing-Best-Practices-1.jpg?fit=785%2C349&amp;ssl=1" alt="Unit Testing Naming Conventions and Standards"/></a></figure>



<p class="wp-block-paragraph">I’m going to talk about simple and easy-to-understand Unit Test Naming Conventions and Best Practices that can be followed while writing Unit Testing. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">As we know Naming standards in any format for anything ( code, documents, unit tests, etc) are always helpful in the long run. The naming standard brings uniformity and avoids ambiguity.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Today in this article, we will cover below aspects,</p>



<p class="wp-block-paragraph"></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-developers-confusion-on-naming">Developer&#8217;s Confusion on Naming ??</a></li><li><a href="#aioseo-naming-pattern-for-unit-testing">Naming Pattern for Unit Testing</a></li><li><a href="#aioseo-unit-test-project-naming-convention">Unit Test Project Naming Convention</a><ul><li><a href="#aioseo-app-name-unit-tests">[App-Name].Unit.Tests</a></li></ul></li><li><a href="#aioseo-unit-test-files-naming-convention">Unit Test Files Naming Convention</a><ul><li><a href="#aioseo-classnametests">[ClassName]Tests</a></li></ul></li><li><a href="#aioseo-unit-test-class-naming-convention">Unit Test Class Naming Convention</a><ul><li><a href="#aioseo-classnametests">[ClassName]Tests</a></li></ul></li><li><a href="#aioseo-unit-test-method-naming-convention">Unit Test Method Naming Convention</a><ul><li><a href="#aioseo-pattern">Pattern :</a></li><li><a href="#aioseo-unitofwork_method_behaviour">[UnitOfWork]_[Method]_[Behaviour]</a></li></ul></li><li><a href="#aioseo-unit-test-structure">Unit Test Structure</a><ul><li><a href="#aioseo-pattern">Pattern:</a><ul><li><a href="#aioseo-act---arrange---assert">Act &#8211; Arrange &#8211; Assert</a></li><li><a href="#aioseo-given-when-then">Given-When-Then</a></li></ul></li></ul></li><li><a href="#aioseo-summary">Summary</a></li></ul></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Coming to Unit testing naming, however, we don&#8217;t really need to get crazy. However, by following them we get multiple benefits. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Following such naming doesn&#8217;t require any extra effort, as once put into practice, you enjoy all their benefits.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">In our last article, we understood general <a href="https://www.thecodebuzz.com/unit-testing-best-practices/" target="_blank" rel="noreferrer noopener" title="Unit Test Best Practices in Software Development"><em><strong>best practices for writing the unit test cases</strong></em></a>. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">However today in this article we will focus primarily on the naming conventions </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Today we will see how to use the naming convention for,</p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li>Test Method</li>
</ul>



<ul class="wp-block-list">
<li>Test Class</li>
</ul>



<ul class="wp-block-list">
<li>Test Project</li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-developers-confusion-on-naming">Developer&#8217;s Confusion on Naming ??</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">This is a small but very common problem among developers. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">There is always confusion in the Developer community on how to name and structure Unit Test cases properly. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Most often developer ends up writing their test cases without any guidelines resulting in issues like tests are not readable, not properly structured, and difficult in troubleshooting, especially on the build server where thousands of test cases run daily.</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large"><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="1607" height="924" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-1.jpg?fit=785%2C452&amp;ssl=1" alt="Unit Testing Naming Standards" class="wp-image-6736" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-1.jpg 1607w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-1-300x172.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-1-1024x589.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-1-768x442.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-1-1536x883.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-1-785x451.jpg 785w" sizes="auto, (max-width: 1607px) 100vw, 1607px" /></a></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-naming-pattern-for-unit-testing">Naming Pattern for Unit Testing</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">As we discussed in our last article on Unit testing best practices, it&#8217;s important to understand that while writing actual unit test cases everything is drilled down to finally <strong>Classes </strong>and <strong>Functions</strong>. </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">These two entities are required to be unit tested in isolation for a given functionality implemented in methods.</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://i2.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/UnitTest-Best-practices-flow.png?fit=785%2C393&amp;ssl=1" alt="Unit Testing Naming Conventions and Standards" class="wp-image-6710" width="454" height="227" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/UnitTest-Best-practices-flow.png 1535w, https://thecodebuzz.com/wp-content/uploads/2019/11/UnitTest-Best-practices-flow-300x150.png 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/UnitTest-Best-practices-flow-1024x513.png 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/UnitTest-Best-practices-flow-768x385.png 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/UnitTest-Best-practices-flow-785x393.png 785w" sizes="auto, (max-width: 454px) 100vw, 454px" /></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-unit-test-project-naming-convention">Unit Test Project Naming Convention</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">The below examples are just guidelines to help you with the naming pattern for the Test project.</p>



<p class="wp-block-paragraph"></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">You are free to use your own customized naming pattern as required. Below are just few suggestions based on my experience. 😉</p>
</blockquote>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Pattern: </strong></p>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading" id="aioseo-app-name-unit-tests">[App-Name].Unit.Tests</h3>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Example: BooksApi.Unit.Tests</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="998" height="273" src="https://www.thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-project-names.jpg" alt="Unit Testing Naming Conventions and Standards" class="wp-image-6724" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-project-names.jpg 998w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-project-names-300x82.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-project-names-768x210.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-project-names-785x215.jpg 785w" sizes="auto, (max-width: 998px) 100vw, 998px" /></figure>



<p class="wp-block-paragraph">Other conventions like  BooksApi-Unit-Tests can also be used if found suitable.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-unit-test-files-naming-convention">Unit Test Files Naming Convention </h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Files can be named after the class names you are dealing with &#8230;</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Pattern:</strong></p>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading" id="aioseo-classnametests">[ClassName]Tests</h3>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Example:</strong> BookServiceTests.cs</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-file.jpg" alt="Unit test name example" class="wp-image-6725" width="449" height="530" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-file.jpg 567w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-file-254x300.jpg 254w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-file-441x520.jpg 441w" sizes="auto, (max-width: 449px) 100vw, 449px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Tips:</strong></p>



<ul class="wp-block-list">
<li>Every class with the public method (at least one method) should have a test file created. (This also means you should refactor your files as per classes)</li>
</ul>



<ul class="wp-block-list">
<li>Make sure to write unit test cases for all public APIs for each given class.</li>
</ul>



<ul class="wp-block-list">
<li>Each test file should be completely isolated from other files.</li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-unit-test-class-naming-convention">Unit Test Class Naming Convention </h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">You need a test class to encapsulate all your test cases. This test class provides an entry point to test cases depending on the configuration. </p>



<p class="wp-block-paragraph">This also helps to initialize the test data required for test cases.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Pattern:</strong></p>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading" id="aioseo-classnametests">[ClassName]Tests</h3>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Example:  &#8216;EmployeesTests&#8217; where Employee is a class name.</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2113" height="912" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names.jpg?fit=785%2C339&amp;ssl=1" alt="" class="wp-image-6727" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names.jpg 2113w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names-300x129.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names-1024x442.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names-768x331.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names-1536x663.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names-2048x884.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-file-names-785x339.jpg 785w" sizes="auto, (max-width: 2113px) 100vw, 2113px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Tips:</strong></p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li>Name your Test Class as per the business class name. </li>



<li>Each Test Class should be defined in a separate test file as discussed above.</li>



<li>Each Test Class should have a mechanism to initialize mock or test data</li>



<li>Each test class should be public.</li>
</ul>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-unit-test-method-naming-convention">Unit Test Method Naming Convention</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Each Unit test method should be unit tested in isolation. This isolation can be simplified by a Class and all its methods.</p>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading" id="aioseo-pattern">Pattern :</h3>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading" id="aioseo-unitofwork_method_behaviour">[UnitOfWork]_[Method]_[Behaviour]</h3>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Example: BookService_GetBookAsync_InValidBookID_Failure</p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large"><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="1142" height="531" src="https://i2.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-name-1.jpg?fit=785%2C365&amp;ssl=1" alt="Unit Test Naming Conventions Best Practices" class="wp-image-6730" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-name-1.jpg 1142w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-name-1-300x139.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-name-1-1024x476.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-name-1-768x357.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-name-1-785x365.jpg 785w" sizes="auto, (max-width: 1142px) 100vw, 1142px" /></a></figure>



<h2 class="wp-block-heading" id="aioseo-unit-test-structure">Unit Test Structure </h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">One can follow the AAA or  Given-When-Then style pattern while structuring your test cases.</p>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading" id="aioseo-pattern">Pattern:</h3>



<p class="wp-block-paragraph"></p>



<h4 class="wp-block-heading" id="aioseo-act---arrange---assert">Act &#8211; Arrange &#8211; Assert</h4>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">The essential idea of the <strong>AAA </strong>pattern is to break down writing your test into three sections.</p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li><strong>Arrange</strong>: This describes a preconditioned state of the test before you begin to test the behavior you&#8217;re specifying in this scenario.  Helps you create required test preparations, test data, mocking, etc.</li>
</ul>



<ul class="wp-block-list">
<li><strong>Act</strong>&#8211; This section tests the behavior that you&#8217;re specifying. </li>
</ul>



<ul class="wp-block-list">
<li><strong>Assert</strong>&#8211; This section describes the changes you expect due to the defined inputs through arranging and specified behavior through Act. </li>
</ul>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large is-resized"><a href="https://www.thecodebuzz.com/integration-testing-best-practices-agile/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-structure.jpg?fit=785%2C643&amp;ssl=1" alt="Unit Test Naming Conventions Best Practices" class="wp-image-6733" width="569" height="466" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-structure.jpg 1128w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-structure-300x246.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-structure-1024x839.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-structure-768x629.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-naming-conventions-for-test-method-structure-635x520.jpg 635w" sizes="auto, (max-width: 569px) 100vw, 569px" /></a></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Some of you might like one more pattern as below,</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Pattern</strong>:</p>



<p class="wp-block-paragraph"></p>



<h4 class="wp-block-heading" id="aioseo-given-when-then">Given-When-Then&nbsp; </h4>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large is-resized"><a href="https://www.thecodebuzz.com/integration-testing-best-practices-agile/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/image-15.png?fit=785%2C654&amp;ssl=1" alt="Unit Test Naming Conventions Best Practices" class="wp-image-6740" width="561" height="468" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/image-15.png 1109w, https://thecodebuzz.com/wp-content/uploads/2019/11/image-15-300x250.png 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/image-15-1024x853.png 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/image-15-768x640.png 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/image-15-624x520.png 624w" sizes="auto, (max-width: 561px) 100vw, 561px" /></a></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">The above pattern has the same meaning on the structure as defined above for the <strong>AAA </strong>pattern. </p>



<p class="wp-block-paragraph"><strong><em>Given-When-Then</em></strong> is most popular in Behavior-Driven Development&nbsp;(<em><strong>BDD</strong></em>) and Functional Testing.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Do you find the above conventions helpful?</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong><em>References: </em></strong></p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/integration-testing-best-practices-agile/" title="Integration Testing Best Practices in Agile" target="_blank" rel="noreferrer noopener"><strong><em>Integration Testing Best Practices in Agile</em></strong></a></li>
</ul>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/unit-testing-best-practices/" target="_blank" rel="noreferrer noopener" title="Unit Test Best Practices in Software Development"><strong><em>Top 10 Unit Test Best Practices in Software Development</em></strong></a></li>
</ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph" style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size wp-block-paragraph"></p>



<p class="wp-block-paragraph" style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size wp-block-paragraph"></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>Happy Coding </strong>!!</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-summary">Summary</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">In this post, we learned a few basic and easy-to-use naming conventions for Unit Testing. We looked at the different naming convention which is useful for Test Project, Test Files, Test Class, Test method and Test method structure, etc.</p>



<p class="wp-block-paragraph"></p>



<hr>



<p class="wp-block-paragraph"></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p><p>The post <a href="https://thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/">Unit Test Naming Conventions Best Practices</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Unit Test and Mock IOptions in .NET Core</title>
		<link>https://thecodebuzz.com/unit-test-mock-ioption-net-core-ioption-moq-appsettings/</link>
					<comments>https://thecodebuzz.com/unit-test-mock-ioption-net-core-ioption-moq-appsettings/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 25 Oct 2021 18:30:00 +0000</pubDate>
				<category><![CDATA[XP Practices]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[accessing configuration in net core test projects]]></category>
		<category><![CDATA[asp.net core]]></category>
		<category><![CDATA[how to mock appsettings json in net core]]></category>
		<category><![CDATA[ioptionsmonitor unit test]]></category>
		<category><![CDATA[Mock IOptions .net core]]></category>
		<category><![CDATA[mock<ioptionsmonitor]]></category>
		<category><![CDATA[nsubstitute ioptions]]></category>
		<category><![CDATA[options pattern]]></category>
		<category><![CDATA[options.create example]]></category>
		<category><![CDATA[Unit Test and Mock IOptions]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=18843</guid>

					<description><![CDATA[<p>Unit Test and Mock IOptions &#60;T&#62; .NET Core Today in this article, we shall see how to Unit Test and Mock IOptions &#60;T&#62; instance often used in Controller or other modules for injecting the configuration details. Updated November 2026: sections on mocking IOptionsMonitor and IOptionsSnapshot, named options and validation, plus an FAQ. Today in this [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/unit-test-mock-ioption-net-core-ioption-moq-appsettings/">Unit Test and Mock IOptions in .NET Core</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Unit Test and Mock IOptions &lt;T&gt; .NET Core</h1>



<p class="wp-block-paragraph">Today in this article, we shall see how to Unit Test and Mock IOptions &lt;T&gt; instance often used in Controller or other modules for injecting the configuration details.</p>



<p class="tcb-update-note"><em>Updated November 2026: sections on mocking IOptionsMonitor and IOptionsSnapshot, named options and validation, plus an FAQ.</em></p>




<p class="wp-block-paragraph">Today in this article, we will cover below aspects,</p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-unit-test-ioption-without-mock">Unit test IOption without Mock</a></li><li><a href="#aioseo-unit-test-ioption-by-mock-ioption">Unit Test IOption by Mock IOption</a></li></ul></div>



<p class="wp-block-paragraph">The IOptions interface pattern provides access to configuration details in related classes as well as<br>the option to load config data depending on the situation.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">The&nbsp;<strong>IOptions&nbsp;</strong>interface&nbsp;will&nbsp;be&nbsp;used&nbsp;to&nbsp;load&nbsp;the&nbsp;configuration&nbsp;as&nbsp;needed&nbsp;in&nbsp;the&nbsp;program.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Example:</strong></p>



<pre class="wp-block-preformatted has-medium-font-size">public class ProducerController : ControllerBase
     {
         readonly ProducerConfigSettings _producerConfigSetting;
         public ProducerController(IOptions producerConfig)
         {
             _producerConfigSetting = producerConfig.Value;
         }

.

.
     }</pre>



<p class="wp-block-paragraph">The above<strong> </strong>shows <strong>ProducerController </strong>which is a controller class injecting Apsettings.json key-value pair using the IOp<strong>t</strong>ion pattern.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">For more details on <strong>IOption </strong>Pattern, please visit the below article,</p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list"><li><a href="https://www.thecodebuzz.com/configuration-in-net-core-2-1/" target="_blank" rel="noreferrer noopener" title="Configuration in ASP.NET Core"><strong><em>Configuration in ASP.NET Core</em></strong></a></li></ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-unit-test-ioption-without-mock">Unit test IOption without Mock</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">In this approach, you certainly need not have to mock the <strong><em>Apsettings </em></strong>object. You can send test settings details via the settings object as below and test all positive and negative scenarios as required.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Example</strong></p>



<p class="wp-block-paragraph"></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
            //Arrange
            ProducerConfigSettings appSettings = new ProducerConfigSettings() 
            { 
                Key1 = &quot;testkey1&quot;,
                Key2 = &quot;Testkey2&quot; 
            };
            IOptions&lt;ProducerConfigSettings&gt; options = Options.Create(appSettings);
            ProducerController controller = new ProducerController(options);


</pre></div>


<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptions-apsettings-1024x495.jpg" alt="Unit Test and Mock IOptions" class="wp-image-18852" width="783" height="378" srcset="https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptions-apsettings-1024x495.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptions-apsettings-300x145.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptions-apsettings-768x372.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptions-apsettings-1536x743.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptions-apsettings-785x380.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptions-apsettings.jpg 1792w" sizes="auto, (max-width: 783px) 100vw, 783px" /></figure>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="aioseo-unit-test-ioption-by-mock-ioption">Unit Test IOption by Mock IOption</h2>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">In this approach, you can mock the Apsettings object. You can send mocked settings details via the settings object as below and test all positive and negative scenarios as required.</p>



<p class="wp-block-paragraph"></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [7]; title: ; notranslate">
           //Arrange
            ProducerConfigSettings appSettings = new ProducerConfigSettings()
            {
                Key1 = &quot;testkey1&quot;,
                Key2 = &quot;Testkey2&quot;
            };
            var mockIOption = new Mock&lt;IOptions&lt;ProducerConfigSettings&gt;&gt;();
            // We need to set the Value of IOptions to be the SampleOptions Class
            mockIOption.Setup(ap =&gt; ap.Value).Returns(appSettings);
            ProducerController controller = new ProducerController(mockIOption.Object);


</pre></div>


<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="534" src="https://www.thecodebuzz.com/wp-content/uploads/2021/10/how-to-initialize-ioptionappsettings-for-unit-testing-1024x534.jpg" alt="Mock IOptions .net core, unit test IOptions " class="wp-image-18853" srcset="https://thecodebuzz.com/wp-content/uploads/2021/10/how-to-initialize-ioptionappsettings-for-unit-testing-1024x534.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/10/how-to-initialize-ioptionappsettings-for-unit-testing-300x157.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/10/how-to-initialize-ioptionappsettings-for-unit-testing-768x401.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/10/how-to-initialize-ioptionappsettings-for-unit-testing-1536x801.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/10/how-to-initialize-ioptionappsettings-for-unit-testing-785x410.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/10/how-to-initialize-ioptionappsettings-for-unit-testing.jpg 1844w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Finally</strong>, Using any of the above approaches when you run the test cases, it starts using <a href="https://thecodebuzz.com/read-appsettings-json-net-core-integration-test-project/">test/mocked app settings</a>, instead of pulling it from the actual <em><strong>apsettings.jso</strong></em>n file.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="307" src="https://www.thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptionst-1024x307.jpg" alt="Unit Test IOptions" class="wp-image-18850" srcset="https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptionst-1024x307.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptionst-300x90.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptionst-768x230.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptionst-1536x461.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptionst-2048x614.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/10/net-core-unit-testing-mock-ioptionst-785x235.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong><em>References</em></strong>: </p>



<p class="wp-block-paragraph"></p>



<ul class="wp-block-list"><li><a href="https://www.thecodebuzz.com/restful-api-controller-unit-testing-best-practices/" target="_blank" rel="noreferrer noopener" title="RESTFul API/Controller Unit Testing – Best Practices"><strong><em></em></strong></a><strong><em><a href="https://www.thecodebuzz.com/configuration-in-net-core-2-1/" target="_blank" rel="noreferrer noopener"><strong><em>Configuration in ASP.NET Core</em></strong></a></em></strong></li></ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">That&#8217;s all! Happy coding!</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Does this help you fix your issue? </p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Do you have any better solutions or suggestions? Please sound off your comments below.</p>



<p class="wp-block-paragraph"></p>



<hr>



<p class="wp-block-paragraph"></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<h2>How to Mock IOptionsMonitor and IOptionsSnapshot in a Unit Test</h2>

<p>You can&#8217;t use <code>Options.Create</code> for these two interfaces, because it only returns <code>IOptions&lt;T&gt;</code>. For <code>IOptionsMonitor&lt;T&gt;</code> and <code>IOptionsSnapshot&lt;T&gt;</code> you need a stub, a mock or a small hand-written fake.</p>

<h3>How do you stub IOptionsMonitor with Moq or NSubstitute?</h3>

<p><code>IOptionsMonitor&lt;T&gt;</code> exposes <strong>CurrentValue</strong>, not <code>Value</code>, so that&#8217;s the member you set up. A stub is a test double that returns a canned answer and nothing more.</p>

<blockquote class="tcb-plain-english" style="border-left:4px solid #f59e0b;background:#fffbeb;margin:18px 0;padding:10px 16px;font-style:normal"><p><strong>Note: </strong> A stub is like a cardboard cut-out of a shop assistant. It stands in the right place and gives the answer you taped to it, but it can&#8217;t react when you change something.</p></blockquote>

<ul>
<li><strong>Moq:</strong> create a <code>Mock&lt;IOptionsMonitor&lt;ProducerConfigSettings&gt;&gt;</code>, call <code>Setup(o =&gt; o.CurrentValue).Returns(appSettings)</code>, then pass <code>.Object</code> to your class. <code>Mock.Of&lt;IOptionsMonitor&lt;ProducerConfigSettings&gt;&gt;(m =&gt; m.CurrentValue == appSettings)</code> does the same in one line.</li>
<li><strong>NSubstitute:</strong> call <code>Substitute.For&lt;IOptionsMonitor&lt;ProducerConfigSettings&gt;&gt;()</code>, then <code>monitor.CurrentValue.Returns(appSettings)</code>.</li>
<li><strong>IOptionsSnapshot:</strong> same approach, but you set up <code>Value</code>. Remember it&#8217;s scoped, so a stub won&#8217;t warn you if you inject it into a singleton. That mistake only shows up at runtime in the real container.</li>
</ul>

<p>If your code calls <code>Get(name)</code>, set that up too. A loose mock returns <code>null</code> for unconfigured calls.</p>

<h3>How do you simulate a configuration reload without a mocking library?</h3>

<p>Write a small fake that implements <code>IOptionsMonitor&lt;T&gt;</code> and can raise its own change notification. A fake is a working lightweight implementation, unlike a stub, which only returns fixed values.</p>

<p>The fake needs four members:</p>

<ul>
<li><strong>CurrentValue:</strong> returns the stored settings object.</li>
<li><strong>Get(name):</strong> returns the stored object, or one per name if you test named options.</li>
<li><strong>OnChange:</strong> saves the listener and returns an <code>IDisposable</code> that removes it.</li>
<li><strong>Set:</strong> replaces the stored value, then calls the listener with the new value and a name.</li>
</ul>

<h3>How do you test a class that reacts to OnChange?</h3>

<p>Build the fake with starting settings, construct the consumer, call <code>Set</code>, and assert the new behaviour. Say a service subscribes in its constructor and caches <code>Key1</code>.</p>

<ol>
<li><strong>Arrange:</strong> create the fake with <code>Key1 = "testkey1"</code> and pass it to the service.</li>
<li><strong>Assert the baseline:</strong> check the service uses <code>testkey1</code> before any reload.</li>
<li><strong>Act:</strong> call <code>Set</code> with <code>Key1 = "newkey"</code>.</li>
<li><strong>Assert the change:</strong> check the service now uses <code>newkey</code>.</li>
</ol>

<h3>Mock library or hand-written fake?</h3>

<p>Use Moq or NSubstitute for one-off stubs where a test only reads <code>CurrentValue</code>. Write the fake once you have several tests that need reload behaviour, because wiring up callbacks with a mocking library in each test gets noisy fast.</p>




<h2>Frequently asked questions</h2>

<h3><strong>Do I need Moq to mock IOptions&lt;T&gt;, or is Options.Create enough?</strong></h3>
<p>No, <code>Options.Create</code> is enough. <code>Options.Create(new T { ... })</code> in <code>Microsoft.Extensions.Options</code> wraps the instance in an <code>OptionsWrapper&lt;T&gt;</code> and returns <code>IOptions&lt;T&gt;</code>, so you need no mocking library and no DI container. Use Moq with <code>Setup(x =&gt; x.Value).Returns(...)</code> only if your test project already uses it, because a real instance is simpler and has nothing to configure.</p>

<h3><strong>How do I mock IOptionsMonitor&lt;T&gt; and its CurrentValue?</strong></h3>
<p>Use a mocking library or a stub, because <code>Options.Create</code> can&#8217;t build an <code>IOptionsMonitor&lt;T&gt;</code>. With Moq, call <code>Setup(o =&gt; o.CurrentValue).Returns(value)</code> or use <code>Mock.Of&lt;IOptionsMonitor&lt;T&gt;&gt;(m =&gt; m.CurrentValue == value)</code>. With NSubstitute, create it with <code>Substitute.For&lt;IOptionsMonitor&lt;T&gt;&gt;()</code> and then call <code>CurrentValue.Returns(value)</code>.</p>
<p>If you need to test <code>OnChange</code> behaviour, write a small fake class that implements the interface. Give it a <code>Set</code> method that stores the new value and calls the registered listener, so the test can simulate a configuration reload.</p>

<h3><strong>Why does IOptions&lt;T&gt;.Value return an unconfigured object in my test?</strong></h3>
<p>Because <code>Value</code> reads the default, empty-string name, and nothing populated that instance. If the options were configured under a name, or the test never set any properties, you get a default object with no error. Use <code>Options.Create</code> with populated values instead. For named options, inject <code>IOptionsMonitor&lt;T&gt;</code> or <code>IOptionsSnapshot&lt;T&gt;</code> and call <code>Get(name)</code>.</p>

<h3><strong>Should I build a real configuration with ConfigurationBuilder in tests instead of a mock?</strong></h3>
<p>Yes, when the thing under test is the configuration itself. Use a real in-memory configuration (<code>AddInMemoryCollection</code> with <code>Bind</code> or <code>services.Configure</code>) to check section names, binding and validation. For testing a consumer&#8217;s logic, such as the controller in this article, <code>Options.Create</code> is simpler and keeps the test focused on your own code.</p><p>The post <a href="https://thecodebuzz.com/unit-test-mock-ioption-net-core-ioption-moq-appsettings/">Unit Test and Mock IOptions in .NET Core</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/unit-test-mock-ioption-net-core-ioption-moq-appsettings/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Trunk-Based Development: Best Practices and Examples</title>
		<link>https://thecodebuzz.com/trunk-based-development-best-practices/</link>
					<comments>https://thecodebuzz.com/trunk-based-development-best-practices/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 02 Sep 2021 02:43:00 +0000</pubDate>
				<category><![CDATA[CICD]]></category>
		<category><![CDATA[XP Practices]]></category>
		<category><![CDATA[Benefits of Trunk Based Development]]></category>
		<category><![CDATA[GitFlow Vs Trunk Development]]></category>
		<category><![CDATA[Trunk Based Development]]></category>
		<guid isPermaLink="false">https://thecodebuzz.com/?p=5173</guid>

					<description><![CDATA[<p>What trunk-based development is and how to do it: short-lived branches, feature flags, release branches and CI rules, with tested Git commands.</p>
<p>The post <a href="https://thecodebuzz.com/trunk-based-development-best-practices/">Trunk-Based Development: Best Practices and Examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>Trunk-based development</strong> is a branching strategy where everyone merges small changes into one shared branch (the trunk, usually <code>main</code>) at least once a day, instead of working for weeks on long-lived feature branches. If your merges are painful, your releases are late or your branches drift away from <code>main</code>, this is the model most CI/CD guidance points to. This guide covers what it is, when it fits, ten practices, and Git commands and a feature flag example that were run for this post.</p>



<p class="wp-block-paragraph">The definitions come from <a href="https://dora.dev/capabilities/trunk-based-development/" target="_blank" rel="noopener">DORA (Google Cloud)</a> and <a href="https://trunkbaseddevelopment.com/" target="_blank" rel="noopener">trunkbaseddevelopment.com</a>, linked where used. The Git and C# examples were run on Git 2.50.1 and .NET SDK 10.0.401. Team-process advice reflects those sources and general practice, not a measurement of your team.</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://thecodebuzz.com/wp-content/uploads/2026/11/tbd-short-vs-long-branches.gif" alt="Schematic animation comparing trunk-based development, where short-lived branches merge into main within hours, with a long-lived feature branch that drifts and ends in one large merge"/></figure>


<p><em>Schematic drawing of the idea, not real repository data.</em></p>


<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#what-is-tbd">What is trunk-based development?</a></li><li><a href="#aioseo-origin-and-merge-hell">Origin and merge hell: why trunk-based development exists</a></li><li><a href="#aioseo-is-it-feasible-to-follow-the-trunk-master-approach">Is trunk-based development feasible for your team?</a></li><li><a href="#aioseo-feature-toggle---inevitable">Feature toggles (flags) keep unfinished work off</a></li><li><a href="#aioseo-benefits-of-trunk-based-development">Benefits of trunk-based development</a></li><li><a href="#aioseo-best-practices-of-trunk-based-development">Best practices of trunk-based development</a></li><li><a href="#common-problems">Common problems and what was tested</a></li><li><a href="#aioseo-summary">Summary</a></li><li><a href="#faq">FAQ</a></li></ul></div>



<h2 class="wp-block-heading" id="what-is-tbd">What is trunk-based development?</h2>



<p class="wp-block-paragraph">DORA describes two patterns. With feature branches, a developer or a group works in isolation until the feature is done, then merges it. With trunk-based development, each developer divides the work into small batches and merges into the trunk at least once, potentially several times, a day. DORA says branches in this model typically last no more than a few hours. The trunkbaseddevelopment.com site defines it as collaborating on code in a single branch called the trunk and resisting pressure to create other long-lived development branches. The trunk is called <code>main</code> in modern Git (older repositories use <code>master</code>).</p>



<h2 class="wp-block-heading" id="aioseo-origin-and-merge-hell">Origin and merge hell: why trunk-based development exists</h2>



<p class="wp-block-paragraph">Long-lived branches collect changes that nobody else has seen. When they finally merge, the merge is large, conflicts are numerous, and the combined code has never been built or tested together. DORA notes that this style often needs extra stabilizing work and code freeze periods, because large merges frequently introduce bugs. Trunk-based development attacks the cause: keep each integration small, and do it often, so conflicts stay small and are found while the change is still fresh.</p>



<h2 class="wp-block-heading" id="aioseo-is-it-feasible-to-follow-the-trunk-master-approach">Is trunk-based development feasible for your team?</h2>



<p class="wp-block-paragraph">Yes, with the supporting practices below. The model scales in two forms, according to the <a href="https://trunkbaseddevelopment.com/" target="_blank" rel="noopener">trunkbaseddevelopment.com</a> site: very small teams may commit directly to the trunk, while larger teams use short-lived branches reviewed through pull requests before merging. It also expects automated tests that run on every change; DORA calls trunk-based development a required practice for continuous integration, which is the combination of frequent merges with a fast automated test suite.</p>



<p class="wp-block-paragraph">It fits poorly when releases are tied to a long manual QA cycle you cannot automate, or when the team cannot keep the build green. Those are the problems to fix first. The same site says teams also need a build server to verify that commits have not broken the build once they land.</p>



<h2 class="wp-block-heading" id="aioseo-feature-toggle---inevitable">Feature toggles (flags) keep unfinished work off</h2>



<p class="wp-block-paragraph">If you merge daily, you will merge code that is not finished. A feature flag lets that code reach the trunk and production while staying switched off. The feature flags page on the same site describes flags as a standard way to control capabilities, at the size of a whole component or something small. A minimal C# example, using an environment variable as the flag source:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
var config = new ConfigurationBuilder()
    .AddEnvironmentVariables()
    .Build();

// Features__DiscountCode=true turns it on (double underscore maps to &quot;:&quot;)
bool.TryParse(config&#x5B;&quot;Features:DiscountCode&quot;], out bool discountEnabled);

decimal total = 100m;
if (discountEnabled)
{
    total = ApplyDiscount(total);   // merged to trunk, dark until the flag is on
}
Console.WriteLine($&quot;Total: {total}&quot;);

static decimal ApplyDiscount(decimal amount) =&gt; amount * 0.9m;
</pre></div>


<p class="wp-block-paragraph">Compiled with <code>Microsoft.Extensions.Configuration.EnvironmentVariables</code> 10.0.0 and run twice. Without the variable the output was <code>Total: 100</code>. With <code>Features__DiscountCode=true</code> it was <code>Total: 90.0</code>. The new code is in the trunk in both runs, but only one of them uses it. Flags are temporary: remove the flag and the old path after the rollout, or the code accumulates dead branches. More on flag hygiene in <a href="https://thecodebuzz.com/feature-toggle-best-practices/">feature toggle best practices</a>.</p>



<p class="wp-block-paragraph">For a change too big for one flag, the same site describes <em>branch by abstraction</em>: put an abstraction in front of the old code, build the new implementation behind it in small commits on the trunk, then switch over.</p>



<h2 class="wp-block-heading" id="aioseo-benefits-of-trunk-based-development">Benefits of trunk-based development</h2>



<ul class="wp-block-list">
<li><strong>Smaller merges.</strong> DORA says fewer development lines and small, frequent merges reduce the complexity of merge events.</li>

<li><strong>Earlier feedback.</strong> Others see your work the same day, and CI tests the integrated result.</li>

<li><strong>Releasable trunk.</strong> If every merge is production-ready, a release is a decision, not a project.</li>

<li><strong>No integration phase.</strong> There is less need for code freezes and stabilization weeks.</li>
</ul>



<p class="wp-block-paragraph">These benefits depend on the practices below. Merging daily without tests mostly moves the pain into production. No figures are claimed here for your team; measure your own lead time and failed-change rate before and after.</p>



<h2 class="wp-block-heading" id="aioseo-best-practices-of-trunk-based-development">Best practices of trunk-based development</h2>



<h3 class="wp-block-heading" id="aioseo-develop-on-the-trunk-master">Develop on the trunk (master)</h3>



<p class="wp-block-paragraph">Treat the trunk as the only long-lived development line. Everyone starts from it and returns to it. Pull the latest trunk before starting and again before merging, so your change is tested against what everybody else just merged.</p>



<h3 class="wp-block-heading" id="aioseo-feature-branch-life-span-a-few-days1-3-days">Keep the feature branch life short</h3>



<p class="wp-block-paragraph">The old rule of thumb on this page was one to three days. The sources are stricter: DORA describes branches that last no more than a few hours, and the <a href="https://trunkbaseddevelopment.com/short-lived-feature-branches/" target="_blank" rel="noopener">short-lived feature branches</a> page counts time spent waiting for review toward the branch&#8217;s life. Pick a limit you can enforce, such as merging within a working day, and treat anything older as a signal to split the work or hide it behind a flag.</p>



<h3 class="wp-block-heading" id="aioseo-create-feature-branches-from-master-trunk">Create feature branches from the trunk</h3>



<p class="wp-block-paragraph">Branch from the current trunk, never from another feature branch. Stacked branches recreate the long-lived branch problem one level down.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
git switch main
git pull --ff-only
git switch -c add-discount-flag
</pre></div>


<h3 class="wp-block-heading" id="aioseo-feature-branches-can-be-aligned-with-the-small-feature-and-hence-user-stories-or-task">Align branches with a small story or task</h3>



<p class="wp-block-paragraph">One branch, one small change that a reviewer can read in minutes. If a story needs a week, split it into steps that each leave the trunk working, for example: add the flag, add the data model, add the endpoint, then switch the flag on.</p>



<h3 class="wp-block-heading" id="aioseo-clean-merges-to-trunk-master">Clean merges to the trunk<span id="aioseo-merges-to-trunk-master"></span></h3>



<p class="wp-block-paragraph">Before merging, fetch, rebase onto the trunk and fast-forward. This keeps history linear and shows exactly what you changed. This sequence was run in a scratch repository with a local bare remote (Git 2.50.1):</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
git fetch origin
git rebase origin/main          # Current branch add-discount-flag is up to date.
git switch main
git merge --ff-only add-discount-flag
git push origin main
git branch -d add-discount-flag
</pre></div>


<p class="wp-block-paragraph">The merge fast-forwarded (<code>Updating 2ab3a57..7446bc8, Fast-forward</code>), the branch was deleted, and the log showed a straight line: <code>7446bc8 Add discount code behind flag, off by default</code> on top of <code>2ab3a57 Initial app</code>. A squash merge in your hosting tool gives the same linear result.</p>



<h3 class="wp-block-heading" id="aioseo-dont-commit-to-master-trunk-directly">Do not commit to the trunk directly (unless your team is tiny)</h3>



<p class="wp-block-paragraph">The old advice here was an absolute rule. The more accurate version: the <a href="https://trunkbaseddevelopment.com/" target="_blank" rel="noopener">trunkbaseddevelopment.com</a> site says very small teams may commit directly, and that short-lived branches with review are used as teams grow. Whichever you choose, protect the trunk so nobody pushes unreviewed or failing code. On GitHub, <a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches" target="_blank" rel="noopener">protected branch rules</a> can require pull request reviews and passing status checks before merging.</p>



<h3 class="wp-block-heading" id="aioseo-merge-should-be-from-a-feature-branch-to-master-trunk">Merge from a feature branch to the trunk</h3>



<p class="wp-block-paragraph">Short-lived branches flow into the trunk. Do not make the trunk depend on another long-lived branch, and do not merge a release branch back wholesale. Updating your own branch from the trunk (rebase or merge) is fine.</p>



<h3 class="wp-block-heading" id="aioseo-every-merge-should-be-production-ready">Every merge should be production-ready</h3>



<p class="wp-block-paragraph">Production-ready here means the build passes, tests pass and unfinished work is behind a flag. It does not mean the feature is visible to users. Run the full build and tests locally before pushing, and again in CI. The sources describe doing a full pre-integration build on the developer&#8217;s workstation first.</p>



<h3 class="wp-block-heading" id="aioseo-keep-trunk-master-green">Keep the trunk green</h3>



<p class="wp-block-paragraph">A red trunk blocks everyone. DORA says developers are responsible for keeping the build green and must stop what they are doing when CI fails. If the fix is not obvious, many teams revert the change first, which unblocks everyone sooner than a broken trunk. Make CI fast: slow pipelines push people toward bigger, rarer merges.</p>



<h3 class="wp-block-heading" id="aioseo-release-branch-to-master-branch-merge-should-be-avoided">Avoid merging release branches back to the trunk wholesale</h3>



<p class="wp-block-paragraph">Release branches are optional. Per the <a href="https://dora.dev/capabilities/trunk-based-development/" target="_blank" rel="noopener">DORA</a> description, they are snapshots cut from the trunk, and fixes are made on the trunk first and cherry-picked into the release. Teams that release several times a day need no release branch at all and fix forward. The flow is one way: from the trunk to the release, by cherry-pick. This was run on the same scratch repository:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
git switch -c release/1.0 main          # cut the release from the trunk
git switch main
# ...commit &quot;Fix typo in checkout message&quot; on main (dbc9801)...
git switch release/1.0
git cherry-pick -x dbc9801              # bring the fix into the release
</pre></div>


<p class="wp-block-paragraph">The graph afterwards showed <code>dbc9801</code> on <code>main</code> and the copied commit <code>ae24a21</code> on <code>release/1.0</code>, and <code>-x</code> records the original commit id in the message. For cherry-pick details in different tools see <a href="https://thecodebuzz.com/cherry-pick-in-git-azure-devops-gitlab-github/">cherry-pick in Git, Azure DevOps, GitLab and GitHub</a> and <a href="https://thecodebuzz.com/cherry-pick-in-github-step-by-step/">cherry-pick in GitHub step by step</a>.</p>



<h2 class="wp-block-heading" id="common-problems">Common problems and what was tested</h2>



<ul class="wp-block-list">
<li><strong>Branches live longer than planned.</strong> Split the work, or put the unfinished part behind a flag and merge it.</li>

<li><strong>Merge conflicts every day.</strong> Merge more often and keep changes smaller; large formatting changes should go in on their own.</li>

<li><strong>A broken trunk.</strong> Revert, then fix. Require status checks before merge.</li>

<li><strong>Flags pile up.</strong> Give each flag an owner and a removal date.</li>

<li><strong>Tested:</strong> the Git commands (Git 2.50.1, local bare remote) and the C# flag example (.NET SDK 10.0.401). <strong>Not tested:</strong> any hosted Git service, branch protection settings, merge queues, large teams or monorepos. Practice descriptions rely on the linked DORA and trunkbaseddevelopment.com pages, read on 24 November 2026.</li>
</ul>



<h2 class="wp-block-heading" id="aioseo-summary">Summary</h2>



<ul class="wp-block-list">
<li>Merge small changes into one trunk at least daily; keep branches short-lived (hours, per DORA).</li>

<li>Use flags for unfinished work and branch by abstraction for big changes.</li>

<li>Protect the trunk: reviews and passing checks before merge; revert if it turns red.</li>

<li>Release from the trunk, or cut short-lived release branches and cherry-pick fixes into them.</li>
</ul>



<p class="wp-block-paragraph">Further reading: <a href="https://dora.dev/capabilities/trunk-based-development/" target="_blank" rel="noopener">Trunk-based development (DORA)</a>, <a href="https://trunkbaseddevelopment.com/" target="_blank" rel="noopener">trunkbaseddevelopment.com</a> and <a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches" target="_blank" rel="noopener">About protected branches (GitHub Docs)</a>.</p>



<div class="wp-block-group has-background" style="border-radius:8px;background-color:#b6d9ac;padding-top:20px;padding-right:24px;padding-bottom:20px;padding-left:24px"><div class="wp-block-group__inner-container is-layout-constrained wp-container-core-group-is-layout-0d2d72cd wp-block-group-is-layout-constrained">
<p class="wp-block-paragraph" style="font-size:20px"><strong>Found this useful?</strong></p>



<p class="wp-block-paragraph">Bookmark this page and share it with your team. Get new .NET, cloud and database tutorials in your inbox.</p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noopener">Subscribe to TheCodeBuzz</a></div>
</div>
</div></div>



<h2 class="wp-block-heading" id="faq">FAQ</h2>



<h3 class="wp-block-heading">What is trunk-based development?</h3>



<p class="wp-block-paragraph">A branching strategy where developers merge small changes into a single shared branch, the trunk or main, at least once a day, instead of keeping long-lived feature branches. Any branches that exist are short-lived, and unfinished work is hidden behind feature flags.</p>



<h3 class="wp-block-heading">How long should a branch live in trunk-based development?</h3>



<p class="wp-block-paragraph">DORA describes branches that typically last no more than a few hours, and trunkbaseddevelopment.com counts review waiting time as part of the branch life. A practical limit is to merge within one working day; older branches should be split or put behind a flag.</p>



<h3 class="wp-block-heading">Do you need release branches with trunk-based development?</h3>



<p class="wp-block-paragraph">Not always. Teams that release several times a day can release straight from the trunk and fix forward. Others cut a short-lived release branch from the trunk and cherry-pick fixes into it from the trunk, and do not merge it back wholesale.</p>



<script type="application/ld+json">{"@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [{"@type": "Question", "name": "What is trunk-based development?", "acceptedAnswer": {"@type": "Answer", "text": "A branching strategy where developers merge small changes into a single shared branch, the trunk or main, at least once a day, instead of keeping long-lived feature branches. Any branches that exist are short-lived, and unfinished work is hidden behind feature flags."}}, {"@type": "Question", "name": "How long should a branch live in trunk-based development?", "acceptedAnswer": {"@type": "Answer", "text": "DORA describes branches that typically last no more than a few hours, and trunkbaseddevelopment.com counts review waiting time as part of the branch life. A practical limit is to merge within one working day; older branches should be split or put behind a flag."}}, {"@type": "Question", "name": "Do you need release branches with trunk-based development?", "acceptedAnswer": {"@type": "Answer", "text": "Not always. Teams that release several times a day can release straight from the trunk and fix forward. Others cut a short-lived release branch from the trunk and cherry-pick fixes into it from the trunk, and do not merge it back wholesale."}}]}</script><p>The post <a href="https://thecodebuzz.com/trunk-based-development-best-practices/">Trunk-Based Development: Best Practices and Examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/trunk-based-development-best-practices/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
