Writing Useful Units

I have a simple grid page with which I bind a collection of objects. I also have some simple functions in the grid for editing and saving lines. I would like to write unit tests for this page, but that doesn't make sense to me.

For instance:

Private Sub LoadGrid()
'Populate Collection
grid.datasource = MyCollection
grid.databind()
end sub

I think that Subreally does not need a unit test, but what if it was a function that returned true when the grid was loaded. How do you write unit test for this? What other test should be done on a simple web page?

As always, thanks to everyone who provides any data.

+3
source share
2 answers

How do you write unit test for this?

. BL, MVC, MVP , One True Way ™. , , .

, :

  • , .
  • , .
  • .

, , - (, VB-fu , #):

interface IProductPageModel
{
    int CurrentPage { get; set; }
    int ItemsPerPage { get; set; }
    DataSet ProductDataSet { get; set; }
}

class ProductPageController
{
    public readonly IProductPageModel Model;
    public ProductPageController(IProductPageModel model)
    {
        this.Model = model;
    }

    public void NavigateTo(int page)
    {
        if (page <= 0)
            throw new ArgumentOutOfRangeException("page should be greater than 0");

        Model.CurrentPage = page;
        Model.ProductDataSet = // some call to retrieve next page of data
    }

    // ...
}

, , , unit test. , , silverlight .., - .

, , , :

public class ProductPage : Page, IProductPageModel
{
    ProductPageController controller;

    public ProductPage()
    {
        controller = new ProductPageController(this);
    }

    public DataSet ProductDataSet
    {
        get { return (DataSet)myGrid.DataSource; }
        set { myGrid.DataSource = value; myGrid.DataBind(); }
    }

    protected void NavigateButton_OnCommand(object sender, CommandEventArgs e)
    {
        controller.NavigateTo(Convert.ToInt32(e.CommandArgument));
    }
}

- - . , "", - .

-, ?

, , , , ..

+2

.

,

'Populate Collection

. , null, , 42 . .

(, datareader), , DbDataReader, UI .

, , , , , IIS ( , , )

, , , , tricker, /stubbing/faking ...

+1

Source: https://habr.com/ru/post/1753586/


All Articles