Skip to content

Commit

Permalink
Merge pull request #82 from SCCapstone/treybranch
Browse files Browse the repository at this point in the history
#83 , Testing Deadline for 1/29/23
  • Loading branch information
Twofishsticks authored Jan 28, 2023
2 parents f2cfe28 + 1902c49 commit e9cc97a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 30 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ Deployment will be done with AWS Hosting. After deploying to AWS, visiting the U

# Testing

In 492 you will write automated tests. When you do you will need to add a
section that explains how to run them.
All tests are located under in /testing. They are seperated by Behaviorial tests (/automation), and Unit tests (/unit).

The unit tests are in `/test/unit`.

The behavioral tests are in `/test/automation/`. (Cypress)

## Testing Technology
Go compiler has built-in test functionality
Go compiler has built-in test functionality. In addition, we will be using ([go-rod](https://github.com/go-rod/rod)) to facillitate behaviorial testing.

## Running Tests
go test <- to run all tests
To run tests, first navigate to the correct directory for the desired testing type. These are either /testing/automation, or /testing/unit. While in these directories, you may run the following commands to test.

go test -v -run test_name <- to run individual test
go test <- to run all tests in current directory

go test -v -run test_name <- to run individual test within a test file

go test file_name.go <- to run all tests in a specific file

## Additional Testing Notes
While running behaviorial testing, if a browser is not detected on your machine, the code will automatically download one for testing.

If on a Windows machine, the code will generate a temp file that is marked as suspiscous, and will be labeled as a Trojan, and subsequently quarentined. **DO NOT PANIC!** This file is used to control the testing browser in many different ways, and is crucial to get the tests to function correctly. You can safely release the file from quarentine, which will allow the behaviorial tests to correctly function. If on another machine, such as a Linux or Mac, the file will not raise any issues.. Please see [this issue in go-rod's github](https://github.com/go-rod/rod/issues/739) for more information.

go test file_name.go <- to run tests in a specific file

# Authors
Ethan Speer: [email protected]
Expand All @@ -54,3 +59,5 @@ Trey Sturman: [email protected]
Dan Rochester: [email protected]

Wilson Green: [email protected] (account email [email protected])


12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ module github.com/SCCapstone/BitCrunch
go 1.19

require (
github.com/ysmood/goob v0.4.0 // indirect
github.com/ysmood/gson v0.7.3 // indirect
github.com/ysmood/leakless v0.8.0 // indirect
github.com/gin-gonic/gin v1.8.1
github.com/go-rod/rod v0.112.3
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
)

require (
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.8.1
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/go-rod/rod v0.112.3
github.com/goccy/go-json v0.9.11 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
Expand All @@ -23,7 +21,9 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
github.com/ysmood/goob v0.4.0 // indirect
github.com/ysmood/gson v0.7.3 // indirect
github.com/ysmood/leakless v0.8.0 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/sys v0.0.0-20220913175220-63ea55921009 // indirect
golang.org/x/text v0.3.7 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ=
github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18=
github.com/ysmood/got v0.32.0 h1:aAHdQgfgMb/lo4v+OekM+SSqEJYFI035h5YYvLXsVyU=
github.com/ysmood/got v0.32.0/go.mod h1:pE1l4LOwOBhQg6A/8IAatkGp7uZjnalzrZolnlhhMgY=
github.com/ysmood/gotrace v0.6.0 h1:SyI1d4jclswLhg7SWTL6os3L1WOKeNn/ZtzVQF8QmdY=
github.com/ysmood/gotrace v0.6.0/go.mod h1:TzhIG7nHDry5//eYZDYcTzuJLYQIkykJzCRIo4/dzQM=
github.com/ysmood/gson v0.7.3 h1:QFkWbTH8MxyUTKPkVWAENJhxqdBa4lYTQWqZCiLG6kE=
github.com/ysmood/gson v0.7.3/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg=
Expand Down
69 changes: 55 additions & 14 deletions testing/automation/GoWebBehavior_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,89 @@ package testing

import (
"fmt"
"log"
"os"
"os/exec"
"runtime"
"testing"

models "github.com/SCCapstone/BitCrunch/models"

"github.com/go-rod/rod"
)

// https://github.com/go-rod/rod/blob/master/examples_test.go

func TestMain(m *testing.M) {
fmt.Println("Please note: in order to properly test, please read the Readme!! Otherwise, the browser will NOT connect properly!")
fmt.Println("Building and Activating GoWeb...")
fmt.Println("Making sure that we are in the correct directory...")
cherry := os.Chdir("../../")
if cherry != nil {
// Something happened when trying to change dir!
fmt.Println("chdir didn't work!", cherry)
return
}
fmt.Println("Building an exe file from the Go code...")
cmd := exec.Command("go", "build -o GoWeb.exe") // purposely using specific name
err := cmd.Run()
cmd := exec.Command("go", "build", "-o", "GoWeb.exe") // purposely using specific name
output, err := cmd.CombinedOutput()
if err != nil {
// Something happened when trying to build the codebase!
fmt.Println("Something happened when trying to build the codebase! \n", err)
fmt.Println(fmt.Sprint(err) + ": " + string(output))
//fmt.Println("Something happened when trying to build the codebase! \n", err)
return
}
fmt.Println("Running built exe file...")
cmd = exec.Command(".\\GoWeb.exe") // running the exe to produce a local copy of the webpage
err = cmd.Run()
output, err = cmd.CombinedOutput()
if err != nil {
// Something happened when trying to run the built command!
fmt.Println("Something happened when trying to run the built command! \n", err)
fmt.Println(fmt.Sprint(err) + ": " + string(output))
return
}
browser := rod.New().MustConnect() // opens up the default browser
defer browser.MustClose() // makes sure the browser closes once Tests are complete

fmt.Println("GoWeb activated! Begin Testing...")
fmt.Println("GoWeb activated! Begin Testing...") // will be "connecting" using rod within the tests themselves
m.Run()
fmt.Println("Testing Complete!")

//NOTE: GoWeb.exe isn't stopped (TODO), make sure you delete it before running more tests!
}

func TestBrowser(t *testing.T) {
newfloorList := models.GetAllFloors()
fmt.Println(newfloorList[0]) // placeholder
func TestPageRunning(t *testing.T) {

browser := rod.New().MustConnect() // opens up the default browser
defer func() {
_, err := browser.Pages()
if err != nil { // check to see if the page was rendered at all
t.Errorf("There was an issue rendering the webapp!")
}
browser.MustClose() // On panic (and end), close the browser
}()
browser.MustPage("http://localhost:80/") // creates a page from browser, connects to localhost
}

func TestLogin(t *testing.T) { // opens up the domain and attempts to login using user1 and pass1
t.Errorf("Auto fail this!")
}

func TestThetests(t *testing.T) {
t.Errorf("Used to test TestMain's functions, make sure to comment out once done!")
}

// Helper function to open correct browser for testee's machine, but does not function properly woth localhost
// thanks to https://gist.github.com/hyg/9c4afcd91fe24316cbf0
func openbrowser(url string) {
var err error

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Fatal(err)
}

}

0 comments on commit e9cc97a

Please sign in to comment.