How do you know which test will best represent the function you want to create?

Development based on Wikipedia testing first speaks of developing a test that will fail because the function does not exist. Then create the code to pass the test. What does this test look like?

How do you know which test will best represent the function you want to create?

Can someone give an example?

As if I made the function of the logout button in a web application, will the test hit the page looking for the button? or what?

I heard that the test test is good for regression testing, I just don’t know how to start integration with my work.

+3
source share
6 answers

, , , TDD, , frontend - , TDD. .

WATIN WebAii . :

  • , ... ,
  • , , , - , , .

, . , - MVC.

+2

?

3 .

  • , ,

, , ? ( , ), "" . , , , .

- ? . isa , Ruby Test:: Unit

readme. BDD

class UserTest < Test::Unit::TestCase
    context "A User instance" do
      setup do
        @user = User.find(:first)
      end

      should "return its full name" do
        assert_equal 'John Doe', @user.full_name
      end

      context "with a profile" do
        setup do
          @user.profile = Profile.find(:first)
        end

        should "return true when sent #has_profile?" do
          assert @user.has_profile?
        end
      end
    end
  end

-, , ? ?

3 .

( , , , TDD). A unit test . , , , ( , "" ).

. . API , , , . , - ( ).

, . , , Selenium Waitr. , , , ( ), (, ).

+1

unit test , (, , )

, , ( ) TDD, :

0

, . , , NUnit MSTest ( .Net-).

-, , unit test - , -. , , , . MVC NUnit Moq:

[Test]
public void LogoutActionShouldLogTheUserOut()
{
    var mockController = new Mock<HomeController>() { CallBase = true };
    var result = mockController.Object.Logout() as ViewResult;

    Assert.That(result.ViewName == "LogoutSuccess", 
                "Logout function did not return logout view!");
}

, , "LogoutSuccess", - . HttpContext - , :)

, . , , , - . , Selenium, -, .

0

, , . TDD ASP.NET WebForms, ASP.NET MVC, HTTP- WebForms, Session, Application, ViewState .., ASP.NET MVC.

Assange Act Assert.

// Arrange
... setup needed elements for this atomic test

// Act
... set values and/or call methods

// Assert
... test a single expected outcome

, , . , .

0

, , ( ).

First of all, write a test that says f(10) == 11, then do it f(10) != 10. Then write a function that passes these tests. If you understand that functions need more features, add more tests.

0
source

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


All Articles