Get immediate access to this and 4,000+ other videos and books.

Take your career further with a raywenderlich.com Pro subscription. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it’s simply the best investment you can make in your development career.

Challenge: Add ViewModel Test Pro

The student materials have been reviewed and are updated as of July 2022.

Prove out your understanding of writing ViewModel tests by adding a test

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

You first challenge for the course is to add another test on the CreatureViewModel to make sure that a creature without strength cannot be saved. The test will be very similar to the test we already wrote to make sure that a creature without a name cannot be saved. Go ahead and pause the video, and take a shot at writing this new test. Unpause when you’re ready to see a solution.

  @Test
  fun testCantSaveCreatureWithoutStrength() {
    creatureViewModel.intelligence = 10
    creatureViewModel.strength = 0
    creatureViewModel.endurance = 7
    creatureViewModel.drawable = 1
    creatureViewModel.name = "My Creature"
    val canSaveCreature = creatureViewModel.canSaveCreature()
    assertEquals(false, canSaveCreature)
  }

Reviews

Comments