Please download to get full document.

View again

of 15

Tests unitaires

1. Tests unitaires Martin Yung 18 septembre 2019 2.  Quels sont les tests unitaires ?  Concept  Identifier les cas de test  Connaître les outils (.NET Core)…
0 views15 pages
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Documenttranscript
  • 1. Tests unitaires Martin Yung 18 septembre 2019
  • 2.  Quels sont les tests unitaires ?  Concept  Identifier les cas de test  Connaître les outils (.NET Core)  TDD
  • 3. Les tests unitaires ne sont pas…. les tests d’intégration
  • 4. Les tests unitaires nous permettent d’isoler un composant et de le tester sans ses dépendances
  • 5. Stub ou mock ?  Stub  Mock
  • 6. Etes-vous un bon dév ? public class FourWheelDrive { private IEnumerable<IWheel> _wheels; public FourWheelDrive(IEnumerable<IWheel> wheels) { _wheels = wheels; } public bool Turn(IWheel wheel, float angleInDegree) { wheel.Turn(angleInDegree); return true; } }
  • 7. Etes-vous un bon dév ? public bool Turn(IWheel wheel, float angleInDegree) { if (wheel == null) { throw new ArgumentNullException(nameof(wheel)); } if (angleInDegree < 0 || angleInDegree >= 360) { throw new ArgumentOutOfRangeException(nameof(angleInDegree)); } wheel.Turn(angleInDegree); return true; }
  • 8. Arrange, act, assert…  AAA (Arrange – Act – Assert)  GWT (Given – When – Then)
  • 9. Cas de test  Cas nominaux  Cas d’erreur
  • 10. Cas nominal [Fact] public void FourWheelDrive_Turn() { // Arrange var wheelStubs = Enumerable.Repeat(new WheelStub(), 4); var fourWheelDrive = new FourWheelDrive(wheelStubs); // Act var wheelStub = new WheelStub(); var isTurned = fourWheelDrive.Turn(wheelStub, 10); // Assert Assert.True(isTurned); }
  • 11. Cas d’erreur [Fact] public void FourWheelDrive_Turn_ExpectsArgumentOutOfRangeException() { // Arrange var wheelStubs = Enumerable.Repeat(new WheelStub(), 4); var fourWheelDrive = new FourWheelDrive(wheelStubs); // Act var wheelStub = new WheelStub(); Action func = () => fourWheelDrive.Turn(wheelStub, 1000); // Assert var ex = Assert.Throws<ArgumentOutOfRangeException>(func); Assert.IsType<ArgumentOutOfRangeException>(ex); }
  • 12. Outils (.NET Core)  xUnit.net  NUnit
  • 13. TDD  = Test Driven Development  Principle  Ecrire d’abord les tests unitaires, ils sont en rouge  Ecrire les lignes de code pour passer les tests au vert  Réorganiser vos codes  Un autre nom : « Red-Green Testing »
  • 14. Ce que nous avons vu  Les tests unitaires  Cas de test  Outils (.NET Core)  TDD
  • 15. Merci 
  • Advertisement
    MostRelated
    View more
    We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks
    SAVE OUR EARTH

    We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

    More details...

    Sign Now!

    We are very appreciated for your Prompt Action!

    x