Skip to content

Unit tests #33

@zacck-zz

Description

@zacck-zz
Contributor
No description provided.

Activity

zacck-zz

zacck-zz commented on Apr 5, 2017

@zacck-zz
ContributorAuthor

Hello guys!
So I am trying to implement unit tests for the application. I understand that currently we only have sample tests. Can anyone advice on a test runner to use for this and any documentation to guide if possible.

akabiru

akabiru commented on Apr 5, 2017

@akabiru
Collaborator

@zacck the test runner is already defined. We integrated elm-test for that.

zacck-zz

zacck-zz commented on Apr 5, 2017

@zacck-zz
ContributorAuthor

@akabiru aweh! So I am having a tiny problem: I added a new sample test file
sampletest.elm

myTest = test "Example Test" (assert True)

But when I run yarn test the only tests that run and pass are the ones that passed before I added mine, So mine neither passes nor fails vis a vis doesn't run. I suspect I am adding the test wrongly could you run me through adding a test? Much Regards!

zacck-zz

zacck-zz commented on Apr 5, 2017

@zacck-zz
ContributorAuthor

Ok I think I have a handle on this I have now got a test failing.
Great Success.
My new Test goes as follows,
Sample

module Sample exposing (..)
import Test exposing(..)
import Expect
all : Test
all =
  describe "New Test Case"
      [ sampleTest]

sampleTest : Test
sampleTest =
    describe "Sample 1"
    [ test "New Test" <|
      \() ->
        Expect.equal(3 + 3) 7]

My current issue is that I can't run this in conjunction with the other existing tests i.e Tests

I have changed TestRunner as such

port module TestRunner exposing (..)

import Tests
import Test.Runner.Node exposing (run, TestProgram)
import Json.Encode exposing (Value)
import Sample


main : TestProgram
main =
    run emit Sample.all


port emit : ( String, Value ) -> Cmd msg

Could anyone help me with running a list as [Sample.all, Tests.all] doesn't yield

akabiru

akabiru commented on Apr 5, 2017

@akabiru
Collaborator

@zacck You're on the right track. Once you have your test in SampleTest.elm

module SampleTest exposing (myTest)

myTest =
    test "Example Test" (assert True)

You can then import the module in Tests.elm and add them to the describe list.

module Tests exposing (..)

import Test exposing (..)
import SampleTest exposing(myTest)
import Expect
import Fuzz exposing (list, int, tuple, string)
import String


all : Test
all =
    describe "Sample Test Suite"
        [ unitTestExample
        , fuzzTestsExample
        , myTest
        ]
-- Rest of the code
zacck-zz

zacck-zz commented on Apr 6, 2017

@zacck-zz
ContributorAuthor

@waiyaki aweh! Ok I think we have handle on this I had to modify your example just a tiny bit so my Tests file ended up looking as such

import String
import Sample


all : Test
all =
    describe "Sample Test Suite"
        [ unitTestExample
        , fuzzTestsExample
        , Sample.sampleTest
        ]

Following this the tests run and my failing test does fail.
Will add a PR to start working on the tests as we document the components and learn what they are supposed to do I can add tests for them.

akabiru

akabiru commented on Apr 6, 2017

@akabiru
Collaborator

Awesome!! Looking forward to that! 🕺🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zacck-zz@akabiru

        Issue actions

          Unit tests · Issue #33 · AndelaOSP/shufflebox-frontend