About 1,440,000 results
Open links in new tab
  1. unit testing - What is the equivalent to JUnit in C# ... - Stack Overflow

    Oct 6, 2008 · I am coming from Java and am currently working on a C# project. What is the recommended way to go about a) unit testing existing C# code and b) accomplishing TDD for C# development? Also is there an equivalent to EMMA / EclEmma (free yet powerful code coverage tool) for Visual Studio and C# code?

  2. In C# Unit test how do equivalent of Java's Spy (instead of …

    Apr 11, 2019 · In C# Unit test how do equivalent of Java's Spy (instead of Mock) to only mock some methods on a class? In Java, when I have a class that calls some other class' static method, I always encapsulate this so I can test it without actually hitting that real resource. For example: public HasSomeStaticCall() this.something = callStaticThing();

  3. Should unit tests be written for getter and setters?

    Jun 1, 2011 · You can write unit tests that have 100% coverage, and yet test absolutely nothing. Unit tests are there to test the behaviour of your code, in an expressive and meaningful way, and getters/setters are only a means to an end.

  4. Best practices for writing unit tests - .NET | Microsoft Learn

    Mar 22, 2025 · The input for a unit test should be the simplest information needed to verify the behavior you're currently testing. The minimalist approach helps tests become more resilient to future changes in the codebase and focus on verifying the behavior over the implementation.

  5. Is it bad practice to make methods public solely for the sake of unit ...

    Mar 2, 2015 · Instead of making all methods to be tested public, and instead of redesigning your classes completely, sometimes the most pragmatic solution is to make the methods in stake "internal" and use the "InternalsVisibleTo" attribute to allow your unit tests access them.

  6. Unit Test Frameworks for C#: The Pros and Cons of the Top 3

    Jul 7, 2023 · The preferred .NET pattern for unit tests is to have a test project for each production (regular) project in your codebase. With MSTest, getting that setup was as easy as File->New Project. Then, when you wrote a test, you could right-click on it and execute, having your result displayed in the IDE.

  7. Unit testing for Java and .Net made simple and free - InfoWorld

    Aug 1, 2003 · When taking a test-first approach to programming (see Test before you leap), developers use unit tests to verify that that their code will function as expected. JUnit and NUnit are open source unit...

  8. Basic Unit Testing with JUnit for C# Developers - DaedTech

    One is that the equivalent of MSTest [TestMethod] is the java @Test annotation. This tells the test runner that this is a unit test. Another thing to note is that I’m using the spring framework’s assert, which may not be applicable if you’re not using Spring MVC.

  9. c# - Should my classes have separate constructors just for unit testing ...

    When I use the default unit test constructor the dependencies don't get created at all. Then, I make most methods public and they don't use the dependencies. Those are the ones I test. "Real" constructors are excluded from code coverage since they can't be tested. If they can't be tested, then you should make them testable.

  10. Should one test the values of an enum using unit tests?

    Sep 27, 2017 · Testing enums for completeness is analogous to testing that all of the representable integers are present. Testing the behaviors that the enumerations support, however, is a good idea.

  11. Some results have been removed
Refresh