Skip to main content
deleted 19 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

unit testing, is Is this a good practice with unit-testing?

iI've created unit test for the "student" CRUD operations that looks like this:

asAs you can see, the region #prepare , contains code that will insert required data to the database forfor the current test to be possible.

isIs it good practice to create a single teststest for each CRUD operation and then call thosethat test inside the tests that require them?!

so what imWhat I'm thinking about would look like this.:

soSo the point is not to write the same code over and over again.

thank you.

unit testing, is this a good practice?

i created unit test for the "student" CRUD operations that looks like this:

as you can see, the region #prepare , contains code that will insert required data to the database for the current test to be possible.

is it good practice to create single tests for each CRUD operation and then call those test inside the tests that require them?!

so what im thinking about would look like this.

so the point is not to write the same code over and over again.

thank you.

Is this good practice with unit-testing?

I've created unit test for the "student" CRUD operations that looks like this:

As you can see, the region #prepare contains code that will insert required data to the database for the current test to be possible.

Is it good practice to create a single test for each CRUD operation and then call that test inside the tests that require them?

What I'm thinking about would look like this:

So the point is not to write the same code over and over again.

edited tags
Link
Simon Forsberg
  • 59.4k
  • 9
  • 156
  • 309
Source Link
Osama
  • 111
  • 1

unit testing, is this a good practice?

i created unit test for the "student" CRUD operations that looks like this:

[Test]
    public void Can_Exec_CrudOps()
    {
        #region Prepare

        
        var account = Processor.Execute(new CreateAccount
        {
            Email = "[email protected]",
            Username = "username",
            Password = "password",
        }).Result;

        #endregion

        var student = Processor.Execute(new CreateStudent
        {
            AccountId = account.EntityID
        }).Result;

        Assert.NotNull(student);
        student.AreEqual(Processor.Execute(new GetStudent
        {
            EntityId = student.EntityID
        }).Result);
        student.AreEqual(Processor.Execute(new GetStudentByAccount
        {
            AccountId = account.EntityID
        }).Result);

        var upd_student = Processor.Execute(new UpdateStudent
        {
            EntityId = student.EntityID,
            Flags = StudentFlags.Active
        }).Result;

        Assert.NotNull(upd_student);
        upd_student.AreEqual(student);
        upd_student.Flags.AreEqual(StudentFlags.Active);

        Processor.Execute(new DeleteStudent
        {
            EntityId = student.EntityID
        });
    }

as you can see, the region #prepare , contains code that will insert required data to the database for the current test to be possible.

is it good practice to create single tests for each CRUD operation and then call those test inside the tests that require them?!

so what im thinking about would look like this.

 [TestFixture]
public class StudentTest : OperationTest
{
    protected override IEnumerable<Type> ModelMappings
    {
        get
        {
            return NHMappings.EDUCATION;
        }
    }

    [Test]
    public void Can_Exec_CrudOps()
    {
        #region Prepare
        // here is what changed //
        var acc = new AccountTests();
        var acc_id=    acc.create_account();
      

        #endregion

        var student = Processor.Execute(new CreateStudent
        {
                        //here too//
            AccountId = acc_id
        }).Result;

        Assert.NotNull(student);
        student.AreEqual(Processor.Execute(new GetStudent
        {
            EntityId = student.EntityID
        }).Result);
        student.AreEqual(Processor.Execute(new GetStudentByAccount
        {
                        // and here//
            AccountId = acc_id
        }).Result);

        var upd_student = Processor.Execute(new UpdateStudent
        {
            EntityId = student.EntityID,
            Flags = StudentFlags.Active
        }).Result;

        Assert.NotNull(upd_student);
        upd_student.AreEqual(student);
        upd_student.Flags.AreEqual(StudentFlags.Active);

        Processor.Execute(new DeleteStudent
        {
            EntityId = student.EntityID
        });
        // and here //
        acc.deleteaccount(acc_id);
    }
}

so the point is not to write the same code over and over again.

thank you.