No applicable method for "accuracy" applied to an object of class "forecast" while knitting R

It's hard to tell what the error is without a reprex (FAQ: What's a reproducible example (`reprex`) and how do I create one?). Here is an example that works with your code.

library(forecast)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

w_data <- ts(abs(rnorm(200)), start = 1968, frequency = 12)
w_training <- window(w_data, start = 1968, end = c(1975, 12))
w_test <- window(w_data, start = 1976)

naive_test <- stlf(w_training, t.window = 13, 
  lambda = BoxCox.lambda(w_training), s.window = "periodic", 
  robust = TRUE, method = "naive", h = length(w_test))
accuracy(naive_test, w_test)
#>                       ME      RMSE       MAE       MPE      MAPE      MASE
#> Training set  0.00394147 0.7864543 0.6299847 -4068.137 4128.5315 0.9773049
#> Test set     -0.17644808 0.6118244 0.5208971  -306.057  327.5739 0.8080756
#>                    ACF1 Theil's U
#> Training set -0.4930051        NA
#> Test set     -0.1100589  0.490973

rwdrift_test <- stlf(w_training, t.window = 13, 
  lambda = BoxCox.lambda(w_training), s.window = "periodic", 
  robust = TRUE, method = "rwdrift", h = length(w_test))
accuracy(rwdrift_test, w_test)
#>                        ME      RMSE       MAE        MPE      MAPE      MASE
#> Training set -0.001135496 0.7866437 0.6304382 -4105.1823 4164.9380 0.9780084
#> Test set     -0.454331138 0.7537172 0.6379784  -425.3502  436.0732 0.9897057
#>                     ACF1 Theil's U
#> Training set -0.49300666        NA
#> Test set     -0.05154857 0.5016373

Created on 2023-01-31 with reprex v2.0.2