func TestMyFunction(t *testing.T) { result := MyFunction(2, 3) if result != 5 { t.Errorf("Expected result to be 5, but got %d", result) } }
func TestCreateUser(t *testing.T) { // Set up database connection db, err := gorm.Open("sqlite3", "test.db") if err != nil { panic("failed to connect database") } defer db.Close() // Run migration db.AutoMigrate(&User{}) // Create user user := User{Name: "John Doe", Email: "[email protected]"} db.Create(&user) // Assert user was created if user.ID == 0 { t.Errorf("Failed to create user") } }In this example, we are testing a function that uses the gorm package to create a new user in a SQLite database. We use the `t.Errorf()` function to print an error message to the console if the user was not created successfully.