What are the main advantages of using NUnit in my application ?

1,928 views
Skip to first unread message

Basanta Padhi

unread,
Jul 11, 2012, 8:39:10 AM7/11/12
to NUnit-Discuss
Hi all,

I am a C# developer and few months before I started implementing NUnit
in my application for Unit testing. For implementing NUnit I always
change my code like:

1) Making all the methods and classes "public"
2) Avoiding return type from a method.
3) removing all the parameters from the methods whose implementing
NUnit
4) to removing parameters from the methods whose implementing NUnit I
am calling them indirectly from another non-parametrized method.

again while going to merge the code I am changing the code according
to my project requirement like:

1) making public access modifier to private.
2) removing extra methods added for implementation of indirect call of
parametrized method etc.

Now I can say I am developing the code because I want to implement
NUnit in my application. Is there any way I can implement NUnit
without changing my code or I am implementing it in a wrong way.

Can anybody please suggest me the main benefits of using NUnit in my
application because currently what ever I am doing by NUnit, that I
can do without using NUnit also. the difference is only GUI which
NUnit provides to me. Apart of this most of the things I can do
without using NUnit also. So what is the need of NUnit implementation
for Unit testing.

I have gone through several links like:
1) http://www.techrepublic.com/article/nunit-allows-effective-unit-testing-with-net-applications/1061780
2) http://xunit.codeplex.com/wikipage?title=Comparisons&ProjectName=xunit
3) http://blogs.msdn.com/b/nnaderi/archive/2007/02/01/mstest-vs-nunit-frameworks.aspx

I found the first link little helpful, but again it is not clearing me
straight way.

Can anybody please help me and share some good article or links or
thoughts to enhance my knowledge in implementing NUnit.

Any help will be appreciated. Thanks in advance....

Charlie Poole

unread,
Jul 11, 2012, 9:52:59 AM7/11/12
to nunit-...@googlegroups.com
Hi Basanta,

Frankly, I would never use a test framework that made me work in the
way you are working! Fortunately, NUnit doesn't require you to work
that way. :-) More inline...

On Wed, Jul 11, 2012 at 5:39 AM, Basanta Padhi
<basanta...@gmail.com> wrote:
> Hi all,
>
> I am a C# developer and few months before I started implementing NUnit
> in my application for Unit testing. For implementing NUnit I always
> change my code like:
>
> 1) Making all the methods and classes "public"

Many developers are happy to keep things public for testing and work
this way. Since you are changing the methods back to private after
testing, I guess you don't want to do it. I suggest that you
1) Investigate other ways to allow your test methods to access the
production methods they need to call.
2) Consider keeping your code less closed. For example, a
collaborating class and it's methods may be public, while the instance
of that class held by other classes remain private.

> 2) Avoiding return type from a method.
> 3) removing all the parameters from the methods whose implementing
> NUnit
> 4) to removing parameters from the methods whose implementing NUnit I
> am calling them indirectly from another non-parametrized method.

I don't understand why you are doing these other things at all.

> again while going to merge the code I am changing the code according
> to my project requirement like:
>
> 1) making public access modifier to private.
> 2) removing extra methods added for implementation of indirect call of
> parametrized method etc.

If you are doing this, then you are not testing the code you
distribute. Don't work this way. Test the same code that will go into
production, otherwise your application is untested.

>
> Now I can say I am developing the code because I want to implement
> NUnit in my application. Is there any way I can implement NUnit
> without changing my code or I am implementing it in a wrong way.

Unit testing with a proper framework does motivate you to make certain
positive changes to your code, which is a good thing. However, I know
of no framework that would require you to make all the changes you are
making - and certainly not NUnit! Perhaps you should give us some
individual examples of changes you make in separate posts and we can
discuss whether they are really needed.

> Can anybody please suggest me the main benefits of using NUnit in my
> application because currently what ever I am doing by NUnit, that I
> can do without using NUnit also. the difference is only GUI which
> NUnit provides to me. Apart of this most of the things I can do
> without using NUnit also. So what is the need of NUnit implementation
> for Unit testing.

Tests can be written without a framework - or you can create your own framework.

What a framework gives you is a uniform structure for creating and
running tests. It provides a discipline that helps you to test
correctly. When using a TDD approach, it helps the design of your code
to emerge as you work and forces you to use certain best practices in
that design.

Charlie

> I have gone through several links like:
> 1) http://www.techrepublic.com/article/nunit-allows-effective-unit-testing-with-net-applications/1061780
> 2) http://xunit.codeplex.com/wikipage?title=Comparisons&ProjectName=xunit
> 3) http://blogs.msdn.com/b/nnaderi/archive/2007/02/01/mstest-vs-nunit-frameworks.aspx
>
> I found the first link little helpful, but again it is not clearing me
> straight way.
>
> Can anybody please help me and share some good article or links or
> thoughts to enhance my knowledge in implementing NUnit.
>
> Any help will be appreciated. Thanks in advance....
>
> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
1> To post to this group, send email to nunit-...@googlegroups.com.
>1 To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>

Basanta Padhi

unread,
Jul 12, 2012, 2:02:50 AM7/12/12
to nunit-...@googlegroups.com
Hi Charlie,

Can you please share a best scenario where we will get benefit of using NUnit? In my case I am taking an example of a simple multiply and add program by reading values from an XML. Now everything from reading, processing data to displaying the output done by using C#.NET. Now clicking on the "Run" from Visual studio is same as clicking "Run" from NUnit tool. So here I think I do not want NUnit testing tool at all as I can do this by the IDE itself. Please rectify me if I am wrong.
>1 To unsubscribe from this group, send email to nunit-discuss+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages