Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:36:01+00:00 2026-06-11T18:36:01+00:00

In a current project, I am dealing with a client who insists that code

  • 0

In a current project, I am dealing with a client who insists that code generation is evil for unit testing. Some of the technical/evaluation staff on their team are extremely experienced developers so this surprises me. So much so, that after seeing their profiles, I am soliciting community opinion on a subject I would not otherwise question (i.e. automation).

The title refers to code generation for creating unit tests. That can be done to various extents depending on the scenario. I wrote this particular library myself and consider it to be very simple in terms of branching, complexity, maintainability, etc. An abstract is listed below to illustrate the same.

The library in question is a generic finite state machine that makes use of two enumerations to determine a list of possible states and commands. Commands are used to specify an abstract transaction while an explicit arbitrary state may also be requested without a command as long as it is legal. Examples of states include Processing, Cancelled, WaitingForUserInput, etc. Examples of commands include WakeUp, Sleep, StartProcessing, etc.

The decleration is as follows:

// Both [TState] and [TCommand] will ALWAYS be enumerations.
public abstract class StateMachineBase<TState, TCommand>: IDisposable
{
    public delegate void DelegateStart (StateMachineBase<TState, TCommand> sender, EventArgs e);
    public delegate void DelegateStop (StateMachineBase<TState, TCommand> sender, EventArgs e);
    public delegate void DelegateTransitionRequest (StateMachineBase<TState, TCommand> sender, TransitionRequestEventArgs<TState, TCommand> e);
    public delegate void DelegateTransitionComplete (StateMachineBase<TState, TCommand> sender, TransitionCompletedEventArgs<TState, TCommand> e);

    public event DelegateStart OnStart = null;
    public event DelegateStop OnStop = null;
    public event DelegateTransitionRequest OnTransitionRequest = null;
    public event DelegateTransitionComplete OnTransitionComplete = null;

    private readonly object _SyncRoot = new object(); // Thread safety.
    public bool Running { get; private set; }
    public TState State { get; private set; }
    private TCommand Command { get; set; }
    private List<Transition<TState, TCommand>> AllowedTransitions { get; set; }

    // Will not work if the machine is running.
    protected void AddTransition (TState from, TState to, TCommand command) { ... }
    public void Start () { ... }
    public void Stop () { ... }
    public bool CanTransit (TState state) { ... }
    public bool CanTransit (TCommand command) { ... }
    public bool Request (TState state) { ... }
    public bool Request (TCommand command) { ... }
}

I do realize that in some cases, using code generation may defeat the purpose of writing unit tests but I am sure many developers do use it in specific scenarios. I figure, if I have written the library myself, I should be able to get the unit tests right whether by hand or reflection.

The question is, is it wise to use code generation in this case? If not, what unintended consequences could I be overlooking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:36:02+00:00Added an answer on June 11, 2026 at 6:36 pm

    I believe very strongly that code generation makes sense for the creation of the test suite infrastructure, but not the business logic. The infrastructure (and you have an example of that in your example above) must be implemented a certain way, but it should be humans (preferably humans who know what they’re doing) who decide on the number of test cases, the purpose for each test case and finally the implementation of the test case logic.

    I would talk to your colleugues to get their opinion on the split between non-negotiable infrastructure code and the stuff that’s let up to the test case author. You should be able to sell them on using code generation for the former and on hand-coding the latter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current project code base has every unit and its friend refined. Extract :-
My current project is broken down into 3 parts: Website, Desktop Client, and a
In my current project, I am writing code generator. The interface would be Command
My current project is split into multiple classes that correctly represent the way we
I am dealing with some HTML text that I basically have read access to.
I'm dealing with an issue with my current employer that has seriously made me
my current project is based on Entity Framwork code-first. I have three types: Task,
My current project involves deploying an upgraded .exe file that runs as a Windows
My current project is about doing some changes in an already build web application
Current project, broke head over this problem: Client Repository: public class ClientRepository { //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.