# Procedure to test locally

**URL:** <https://forum.codecrafters.io/t/procedure-to-test-locally/3727>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [December 27, 2024, 1:02pm UTC](https://forum.codecrafters.io/t/procedure-to-test-locally/3727 "2024-12-27T13:02:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruchisaluja](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/ruchisaluja/32/3757_2.png) [@ruchisaluja](https://forum.codecrafters.io/u/ruchisaluja)\
**Post date:** [December 27, 2024, 1:02pm UTC](https://forum.codecrafters.io/t/procedure-to-test-locally/3727/1 "2024-12-27T13:02:56Z")

</div>

Hi all  
I am building the shell project in Golang. But I am unable to test it on local Windows environment. Installed Golang version : 1.23.4  
Golang version used by Codecrafters tester : 1.22.10  
I changed the version in the go.mod file to 1.23.4 and run go mod tidy after that. But no packages are added to go.mod file. I need some help figuring out the issue in my local setup. TIA!

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 28, 2024, 1:07am UTC](https://forum.codecrafters.io/t/procedure-to-test-locally/3727/3 "2024-12-28T01:07:36Z")

</div>

Hi @ruchisaluja, could you confirm what error messages you’re seeing?

Please note that our testers are run on Linux, so you might need to install WSL to test on Windows.

---

<div class="post-metadata">

**Author:** ![frozar](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/frozar/32/4875_2.png) [@frozar](https://forum.codecrafters.io/u/frozar)\
**Post date:** [February 16, 2025, 8:31pm UTC](https://forum.codecrafters.io/t/procedure-to-test-locally/3727/5 "2025-02-16T20:31:55Z")

</div>

@andy1li  
I also try to run tests locally with golang. I just get back to my first submission for a challenge and try to create a test file `serve_test.go`. Here the code:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/8/8bc2c977fc2bfc08a5ca6e007f0081eee5abe327.png)

When I try to launch the test with the command `go test app/server_test.go`, I get:

```auto
# command-line-arguments [command-line-arguments.test]
app/server_test.go:9:9: undefined: Hello
FAIL	command-line-arguments [build failed]
FAIL

```

You can see that I tried to import the main module at the 5 line of `server_test.go` but it has no chance to work this way.

I also don’t find documentation of this topic at:

> **[Go - CodeCrafters](https://docs.codecrafters.io/challenges/language-support/go)**
>
> Learn how to solve CodeCrafters challenges in Go

Do you have any clue for me too be able to run test locally in golang? It would enable users to write code in a TDD fashion which is a good way to develop a project 😃

---

<div class="post-metadata">

**Author:** ![frozar](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/frozar/32/4875_2.png) [@frozar](https://forum.codecrafters.io/u/frozar)\
**Post date:** [February 20, 2025, 12:04pm UTC](https://forum.codecrafters.io/t/procedure-to-test-locally/3727/7 "2025-02-20T12:04:18Z")

</div>

Hi @andy1li, I just wonder if you had time to read my message and if it was understandable.

Do you think it is in your roadmap for golang?

---

<div class="post-metadata">

**Author:** ![frozar](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/frozar/32/4875_2.png) [@frozar](https://forum.codecrafters.io/u/frozar)\
**Post date:** [February 20, 2025, 6:58pm UTC](https://forum.codecrafters.io/t/procedure-to-test-locally/3727/9 "2025-02-20T18:58:55Z")

</div>

I finally got a synthetic example where I can run a golang unit test in a codecrafters challenge. Here is an image where you can see every part of my tiny test example:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/f/f13e11e2a1ede084b813c42b228cc5ea03cffc03.png)

In the pink rectangle, you can see that I have 2 files in my `app` directory, `server.go` and `server_test.go`. In the green rectangles, you can see I have a `functionToTest()` that returns a string and a `TestHello()` that tests this function. So now, at the root of the repository, I can run this test with the following command:

```sh
$ go test ./app                                                    
ok github.com/codecrafters-io/kafka-starter-go/app	0.003s

```

If you want more details:

```sh
$ go test -v ./app
=== RUN TestHello
--- PASS: TestHello (0.00s)
PASS
ok github.com/codecrafters-io/kafka-starter-go/app	0.002s

```

What is confusing is that if you give directly the path of the test source file, you will get this error:

```sh
$ go test ./app/server_test.go  
# command-line-arguments [command-line-arguments.test]
app/server_test.go:8:9: undefined: functionToTest
FAIL	command-line-arguments [build failed]
FAIL

```

You want to test a subdirectory, `foo`, of `app` directory, you just have to give its path on the command line:

```sh
$ go test ./app/foo

```

@andy1li IMHO, this topic is solved.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [March 9, 2025, 4:01pm UTC](https://forum.codecrafters.io/t/procedure-to-test-locally/3727/10 "2025-03-09T16:01:25Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
